gpt4 book ai didi

android - 如何使用数组适配器?

转载 作者:行者123 更新时间:2023-11-30 04:27:03 25 4
gpt4 key购买 nike

我正在制作一个可以搜索表“员工”并返回结果的应用程序。我如何使用阵列适配器来执行此操作?我是 Android 新手。

public class SimpleSearch extends Activity {
/** Called when the activity is first created. */
protected SQLiteDatabase db;
Intent intent = getIntent();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// Get the intent, verify the action and get the query
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doMySearch(query);
}
}
public List<String> doMySearch(String query) {
List<String> result = new ArrayList<String>();

Cursor c = db.query(
"employee",
new String[] { "_id" }, // The column you want as a result of the Query
"firstName like '%?%' OR lastName like '%?%' OR officePhone like '%?%'", // The where-Clause of the statement with placeholders (?)
new String[] { query, query, query }, // One String for every Placeholder-? in the where-Clause
);
while (c.moveToNext()) {
result.add(c.getString(0));
}
c.close();
return result;
}


}

最佳答案

你不必使用数组适配器,使用SimpleCursorAdapter反而。如果您需要使用它的示例,可以查看 Notepad tutorial .

关于android - 如何使用数组适配器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8308722/

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