android - Cannot start an activity properly from a Listview with Search option -


i have created application supposed show listview searchbox , items user can click on , start new activity, or search specific 1 , same.

right can search item , start activity supposed to, when click without searching, doesn't start properly. example clicking on first 10 items launches 1 same activity instead of 10 different ones.

my code looks -

public class itemmenu extends activity {  private listview lv;  arrayadapter<string> adapter;  edittext inputsearch;   arraylist<hashmap<string, string>> itemlist;  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.item_menu);      string items[] = {"item 1", "item 2", "item 3", "item 4", "item 5",  "item 6", "item 7", "item 8", "item 9", "item 10", "item 11"  etc...     };      lv = (listview) findviewbyid(r.id.itemlistview);     inputsearch = (edittext) findviewbyid(r.id.search_item);      adapter = new arrayadapter<string>(this, r.layout.item_item, r.id.item_item_title, items);     lv.setadapter(adapter);      lv.setonitemclicklistener(new adapterview.onitemclicklistener() {         @override         public void onitemclick(adapterview<?> parent, view view, int position, long id) {             textview textview = (textview)findviewbyid(r.id.item_item_title);             string stext = textview.gettext().tostring();             intent intent = null;             if(stext.equals("item 1"))                intent = new intent(getbasecontext(),                         b1.class);             else if(stext.equals("item 2"))                 intent = new intent(getbasecontext(),                         b2.class);             else if(stext.equals("item 3"))                 intent = new intent(getbasecontext(),                         b3.class);             else if(stext.equals("item 4"))                 intent = new intent(getbasecontext(),                         b4.class);             else if(stext.equals("item 5"))                 intent = new intent(getbasecontext(),                         b5.class);             else if(stext.equals("item 6"))                 intent = new intent(getbasecontext(),                         b6.class);             else if(stext.equals("item 7"))                 intent = new intent(getbasecontext(),                         b7.class);             else if(stext.equals("item 8"))                 intent = new intent(getbasecontext(),                         b8.class);             else if(stext.equals("item 9"))                 intent = new intent(getbasecontext(),                         b9.class);             else if(stext.equals("item 10"))                 intent = new intent(getbasecontext(),                         b10.class);             else if(stext.equals("item 11"))                 intent = new intent(getbasecontext(),                         b11.class);              etc...               if(intent != null)                 startactivity(intent);         }     });      inputsearch.addtextchangedlistener(new textwatcher() {          @override         public void ontextchanged(charsequence cs, int arg1, int arg2, int arg3) {             itemmenu.this.adapter.getfilter().filter(cs);         }          @override         public void beforetextchanged(charsequence arg0, int arg1, int arg2,                                       int arg3) {             // todo auto-generated method stub          }          @override         public void aftertextchanged(editable arg0) {             // todo auto-generated method stub         }     });      } 

}

when click on item logcat shows this:

    w/iinputconnectionwrapper﹕ getselectedtext on inactive inputconnection     w/iinputconnectionwrapper﹕ setcomposingtext on inactive inputconnection     d/sensormanager﹕ unregisterlistener:: trklfufi 9   budiwrd5mrfo5wirfulblrwufmfultrklfufi$kfukwifmfultrklfufirvht@,*--:af(     d/sensors﹕ remain listener = sending .. normal delay 200ms     i/sensors﹕ senddelay --- 200000000     d/sensormanager﹕ jni - senddelay     i/sensormanager﹕ set normal delay = true 

i think problem line because finds view item_item_title in layout:

textview textview = (textview)findviewbyid(r.id.item_item_title); 

but trying find item's view clicked. should use:

textview textview = (textview)view.findviewbyid(r.id.item_item_title); 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -