开发者

onlistitemclick after filtering the listview

开发者 https://www.devze.com 2023-03-13 05:28 出处:网络
I am retreiving 20 names from an sqlite database and displaying them in the form of listview. They are unsorted. I use filter and sort them alphabetically so that I avoid unnecesary scrolling. I have

I am retreiving 20 names from an sqlite database and displaying them in the form of listview. They are unsorted. I use filter and sort them alphabetically so that I avoid unnecesary scrolling. I have an edittext too. When I type a key, it matches the listitems and filters the list. Each listitem has a respective text with it,

The problem now here is, when I sort and filter, the position of the listitem changes. When I click on that, it displays its current positions text and the listitem's text.

For example: I have a 3 DB entries

ROWID NAME       DESCRPTION
1    RASHMI   I AM FRM INDIA
2    RICHA    I AM FROM USA
3    STELLA   I AM FROM CANADA.

My list view displays only the NAME column. Now when I press S in the edittext, STELLA comes up from position 3 to position 1. When I click on that listitem, it开发者_StackOverflow中文版 displays I AM FROM INDIA instead of I AM FROM CANADA. Every action is taking place from SQLite DB.


post your adapter code.

if you are changing the cursor on the adapter as you probably are. be sure to get the cursor from the adapter by calling

    Cursor c = adapter.getCursor()
c.moveToPosition(position);
String description = c.getString(c.getColumnIndex("DESCRIPTION"));

the key thing is to move the cursor to the desired position in the list. also be sure you are using the attached cursor to the listView not a previously saved instance or from your first query when you were assigning it to the adapter.

0

精彩评论

暂无评论...
验证码 换一张
取 消