ITKeyword,专注技术干货聚合推荐

注册 | 登录

android - ListView filtering with CursorLoader and Custom CursorAdapter

itPublisher 分享于

2021腾讯云限时秒杀,爆款1核2G云服务器298元/3年!(领取2860元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1062

2021阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址https://www.aliyun.com/minisite/goods

推荐:Android CursorAdapter

CursorAdapter: 继承于BaseAdapter是个虚类,它为cursor和ListView提供了连接的桥梁. 使用时,Cursor结果集中必须包含列名为“_id”的列,解决方法:     1、修改

I am currently doing a project that involves showing a list of locations nearby based on my current location.

I just started Android Programming not long ago, so I am still at my learning while coding phase.

I searched all over trying to get some clues on how to proceed. I am still stuck after reading and trying out.

My working code currently consists of

  • CursorLoader
  • A custom ResourceCursorAdapter that help populates my entries on the ListView

Questions

  1. What is the "correct" way to filter entries for my ListView? I saw posts on Filter/Filterable interface, but it doesn't seems to work for my current setup? Do I perform filtering inside my Custom CursorAdapter?

  2. How should I refresh my ListView after I perform filtering? Do I call getLoaderManager().restartLoader(0, null, this) or adapter.notifyDataSetChanged() ?

    推荐:Android Tips:CursorAdapter 绑定 ListView后,List滚动CheckBox选中消失的问题

    问题描述:      在CursorAdapter绑定ListView之后,如果List上有Checkbox, 我们会监听onCheckChanged这个函数。 在实际的运用中会出现滚动list之前选中的项目

Thanks in advance.

android android-listview android-cursoradapter android-loadermanager android-cursorloader
|
  this question
asked Sep 30 '13 at 13:41 user2831334 31 1 3

 | 

1 Answers
1

Use getLoaderManager().restartLoader(LOADER_ID, null, MainActivity.this); to recall onCreateLoader.

Android developer site example.

private String filter;
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.action_filter :
            filter = "COLUMN_NAME = value";
            getLoaderManager().restartLoader(LOADER_ID, null, MainActivity.this);           
            break;          
        default:
            break;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public android.content.Loader<Cursor> onCreateLoader(int id, Bundle args) {

        return new CursorLoader(
                MainActivity.this,   // Parent activity context
                SomeContentProvider.CONTENT_URI,        // Table to query
                projection,     // Projection to return
                filter,            // No selection clause
                null,            // No selection arguments
                null             // Default sort order
                );

    }

|
  this answer
edited Nov 7 '13 at 20:43 answered Nov 7 '13 at 20:38 kubo 350 5 15 1   A bit sparse on words, but a useful concept. Upvote. –  Anderson Jul 25 '14 at 21:09

 | 

推荐:深入源码解析Android中Loader、AsyncTaskLoader、CursorLoader、LoaderManager

如果对Loader、AsyncTaskLoader、CursorLoader、LoaderManager等概念不明白或不知道如何使用Loader机制,可参见博文Android中Loader及LoaderManager的使用(附源


相关阅读排行


相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。