gpt4 book ai didi

android - 简单游标适配器查询

转载 作者:行者123 更新时间:2023-11-30 04:12:28 24 4
gpt4 key购买 nike

我创建了一个 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 并覆盖 bindView 应该可行。我通常扩展 CursorAdapter,但尝试一些类似的东西

public class MyAdapter extends SimpleCursorAdapter {

@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView label = view.findViewById(R.id.yourid);
// and then do something with cursor.getString(columnindex);
}
}

关于android - 简单游标适配器查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10620475/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com