android - Get original ID from filtered Listview -


i have class in can put in stringarray, , shows list search box filter contents. application prone every field has set id. however, when search value, ids change filtered list. there way id original list, in filtered list can have ids 9, 14 instead of 0, 1, 2....

 lv1.setadapter(new arrayadapter<string>(this,android.r.layout.simple_list_item_1 , searchitems));     ed.addtextchangedlistener(new textwatcher() {          public void aftertextchanged(editable s) {         }          public void beforetextchanged(charsequence s, int start, int count,                                       int after) {         }          public void ontextchanged(charsequence s, int start, int before,                                   int count) {              textlength = ed.gettext().length();             arr_sort.clear();             (int = 0; < searchitems.length; i++) {                 if (textlength <= searchitems[i].length()) {                     if (ed.gettext().tostring().equalsignorecase((string) searchitems[i].subsequence(0, textlength))) {                         arr_sort.add(searchitems[i]);                     }                 }             }              lv1.setadapter(new arrayadapter<string>(rest_search.this, android.r.layout.simple_list_item_1, arr_sort)); //                lv1.smoothscrolltoposition(20);         }     });     lv1.setonitemclicklistener(new adapterview.onitemclicklistener() {         @override         public void onitemclick(adapterview parent, view v,                                 int position, long id) { //                string = parent.getitematposition(position); //                menuid = (int) id;              int = (int) parent.getadapter().getitemid(position); //                menuid = (int) parent.getadapter().getitemid(position);             toast.maketext(rest_search.this,  ""+a, toast.length_short).show(); 

you can customize adapter. create new class extends basaadapter , override getitemid method:

@override     public long getitemid(int position) {         return items[position].getid();     } 

and in onitemclick use item ids.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -