Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering list view and getting correct onclick item

I have a list view and I've implemente filtering.

Lets say I have items A, B and C. If I type B in the filter box, only item B will be displayed and it is the position 0 of the list (before it was in position 1). So when I call the onClick item, I get the the id/position 0, which leads to displaying details about A instead of B.

This is the onclick code:

ListView lv = getListView();
lv.setTextFilterEnabled(true);

lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {

    Poi poi = pois.get((int)id);
    goPOIDETAIL(poi);

}
});

id and position have the same value.

is there a way to get the original position, or get some other value indicating the real item that I clicked?

Thanks

like image 487
marimaf Avatar asked Dec 06 '12 02:12

marimaf


1 Answers

 flashsearchList.setOnItemClickListener(new OnItemClickListener() {

        @Override 
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            Integer temp=flashSearchNameMap.get(adapter.getItem(position));

            navigateSearch(temp); 



        }
    }); 

(adapter.getItem(position) will return you the exact list name and in flashSearchNameMap i have stored names and position at beginning from oncreate before applying filtering.So you can get exact position by this

like image 166
raja Avatar answered Oct 12 '22 12:10

raja