onItemClick给出可见页面上项目的索引/位置...不是列表中项目的实际索引..启用setTextFilterEnabled时的问题 [英] onItemClick gives index/ position of item on visible page ... not actual index of the item in list ..issue on enabling setTextFilterEnabled

查看:152
本文介绍了onItemClick给出可见页面上项目的索引/位置...不是列表中项目的实际索引..启用setTextFilterEnabled时的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个列表..列表的元素是从sqlite数据库中提取的。我使用ArrayList和ArrayAdapter填充列表...单击列表中的项目我希望能够触发包含关于项目的信息点击...信息像项目的索引号..

I am creating a list .. the elements of the list are drawn from sqlite database .. I populate the list using ArrayList and ArrayAdapter ...upon clicking the items on the list I want to be able to fire an intent containing info about the item clicked ... info like the index number of the item ..

使用方法:
onItemClick(AdapterView av,View v,int index,long arg)

using the method: onItemClick(AdapterView av, View v, int index, long arg)

我确实得到了点击项目的索引。但它是当前显示的列表。问题出现在我做setFilterTextEnabled(true)时,并在应用程序中输入一些文本来搜索某个项目..然后单击它..而不是给我原始列表中项目的索引它给了我索引在筛选列表.. ..

I do get index of the item clicked . however it is of the list currently displayed . the problem comes when I do setFilterTextEnabled(true) , and on the app type in some text to to search some item ..and then click it ..rather than giving me the index of the item on the original list it gives me the index on filtered list..

以下是代码片段:

myListView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> av, View v, int index, long arg) {
            Intent lyricsViewIntent = new Intent(iginga.this, LyricsPage.class);

            lyricsViewIntent.putExtra("title", songList.get((int)arg).getTitle());
            lyricsViewIntent.putExtra("id", songList.get((int)arg).getSongId());
            startActivity(lyricsViewIntent);
        }
    });

    myListView.setTextFilterEnabled(true);

我有什么方法可以得到项目的原始索引/位置而不是显示的项目过滤后的文字...过滤后。

Is there any way I can get the original index /position of the item instead of the one showing in filtered text ...when filtered.

推荐答案

我最近对这个问题进行了一些摔跤,解决方案结果相当简单。您可以在 ListActivity 上使用 getListAdapter()检索可见列表,这反映了当前的筛选视图列表。

I had a bit of a wrestle with this problem recently, and the solution turns out to be fairly simple. You can retrieve the "visible list" by using getListAdapter() on the ListActivity, which reflects the current filtered view of the list.

例如,在你的 ListActivity 子类的 onCreate()

final ListView listView = getListView();
final ListAdapter listAdapter = getListAdapter();

listView .setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        MyClass item = (MyClass) listAdapter .getItem(position);
        // now do something with that item
    }
});

所以,忽略你放入列表适配器的原始列表,而不是要求每次事件进入时都会从适配器列出。

So, ignore the "original" list that you put into the list adapter, and instead ask for the list from the adapter each time the event comes in.

这篇关于onItemClick给出可见页面上项目的索引/位置...不是列表中项目的实际索引..启用setTextFilterEnabled时的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆