1
我已經創建了一個SimpleCursorAdapter。我想要一種方法來比較兩行。 可以說這些列被稱爲realData pracData。如果我想比較兩列,我將如何編寫語句來實現這一點。簡單遊標適配器查詢
下面是我爲我的SimpleCursorAdapter
db = new DBAdapter(this);
db.open();
// db.insertContact("how do you print hello world", "print 'hello world';", "print hello", "hello", 1);
// db.insertContact("what is x=2 and y=5", "5", "7", "2", 2);
db.close();
/*
* Open the same SQLite database
* and read all it's content.
*/
db = new DBAdapter(this);
db.open();
Cursor cursor = db.getAllContacts();
startManagingCursor(cursor);
String[] from = new String[]{DBAdapter.question, DBAdapter.possibleAnsOne};
int[] to = new int[]{R.id.label, R.id.TextView01};
SimpleCursorAdapter cursorAdapter =
new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);
listContent.setAdapter(cursorAdapter);
db.close();
代碼這是一個ArrayAdapter
if (s.startsWith("how do you print hello world") || s.startsWith("iPhone")
|| s.startsWith("Solaris")) {
imageView.setImageResource(R.drawable.plus);
我想要做類似的事情,但在我的數據庫比較兩行。
public class MyAdapter extends SimpleCursorAdapter {
private Context context;
private int layout;
public MyAdapter(Context context, int layout, Cursor c, String[] from,
int[] to) {
super(context, layout, c, from, to);
this.context = context;
this.layout = layout;
// TODO Auto-generated constructor stub
}
@Override
public void bindView(View v, Context context, Cursor c) {
// do your magic inhere :) the cursor will be at the correct row position
System.out.println("please select a cursor");
// int nameCol = c.getColumnIndex(People.NAME);
// ListView listContent = (ListView)findViewById(R.id.contentlist);
// ImageView imageView = (ImageView)findViewById(R.id.ImageView01);
int nameCol = c.getColumnIndex(DBAdapter.question);
System.out.println("What is the column index" +nameCol);
}
}
可以,我想實現的任務與SimpleCursorAdapter做,或者我應該使用CursorAdapter – al23dev
是的,你可以在你更新使用SimpleCursorAdapter – JustDanyul
保持您的問題,現在你想比較兩行?並在你的問題的早些時候,你說你想比較兩列。這是什麼? (你顯然可以做到這一點,但解決方案會有所不同) – JustDanyul