我正在尝试将一些值传递给函数并比较一些值并获取数组列表。
调用 Dbhand 类中的 Collect 函数。
TextView result = (TextView) findViewById(R.id.textviewres);
result.setText(dbhand.collect(
getIntent().getExtras().getString("temple_type"),
getIntent().getExtras().getString("notemples"))
);
dbhand 类中的collect() 函数。
public String collect(String temptype, String limit){
SQLiteDatabase ourDatabase = this.getWritableDatabase();
String result="";
String []column =new String[]{KEY_ID,KEY_TMPNAME,KEY_TMPTYPE,KEY_LATITUDE,KEY_LONGITUDE,KEY_IMGNAME,KEY_YEARBUILD,KEY_ADDRESS,KEY_CITY,KEY_EMAIL,KEY_WEB,KEY_TEL1,KEY_TEL2,KEY_DESCRI};
Cursor c=ourDatabase.query("templ", column, null, null, null, null,null, limit);
c.moveToFirst();
int iKEY_ID = c.getColumnIndex(KEY_ID);
int iKEY_TMPNAME= c.getColumnIndex(KEY_TMPNAME);
int iKEY_TMPTYPE= c.getColumnIndex(KEY_TMPTYPE);
for (c.moveToFirst();!c.isAfterLast();c.moveToNext()){
if (c.getString(iKEY_TMPTYPE) == temptype){
result = result+c.getString(iKEY_ID)+"\t\t"+c.getString(iKEY_TMPNAME)+"\t\t"+c.getString(iKEY_TMPTYPE)+" \n";
}
}
return result;
}
我没有收到任何错误,因为没有比较 if 条件。它不返回任何值。
谁能帮我解决这个问题吗?
最佳答案
这是比较两个字符串的糟糕编程。你应该使用这个。
c.getString(iKEY_TMPTYPE).equalsIgnoreCase(temptype)
关于java - 如果条件不起作用,同时尝试比较数组列表中的值。安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21697855/