首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用arrayadapter?

如何使用arrayadapter?
EN

Stack Overflow用户
提问于 2011-11-29 17:49:11
回答 2查看 340关注 0票数 1

我正在开发一个应用程序,它可以搜索表“employee”并返回结果。如何使用阵列适配器执行此操作?我是android的新手。

代码语言:javascript
复制
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;
    }


}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-11-29 17:56:17

您应该使用ListActivity或ListFragment,并使用CursorAdapter填充它们。(SimpleCursorAdapter)是一个实现类

可以从doMySearchMethod返回的列表中填充CursorAdapter。

票数 0
EN

Stack Overflow用户

发布于 2011-11-29 17:54:58

您不必使用数组适配器,而是使用SimpleCursorAdapter。如果你需要一个使用它的例子,你可以看看Notepad tutorial

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8308722

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档