android setOnItemClickListener in dynamic Listview -


hi :) create dynamically listview. listview changes items flexibility depending on action of user. but program has click event of first list, if list changes. need register new setonitemclicklistener when list every change?


code :

oncreate

final arraylist<item> items = setlist("all"); //set list item dynamically  venueslistadapter adapter = new venueslistadapter(getactivity(), items); mlistview.addheaderview(mheader); mlistview.setadapter(adapter);  mlistview.setonitemclicklistener(new adapterview.onitemclicklistener() {     @override     public void onitemclick(adapterview<?> parent, view view, int position, long id) {         if(position > 1){             log.d(gettag(), ""+items.get(position).gettext());         }     } }); 

when change list (usually when click button)

arraylist<item> items = setlist("barra"); //set list item dynamically mlistview.setadapter(new venueslistadapter(getactivity(), items)); 

add list item dynamically method

arraylist<item> setlist(string type){     arraylist<item> items = new arraylist<item>();      switch (type){          case "all":             items.add(new venueslistheader("all"));             items.add(new venueslistitem("olympic stadium"));             items.add(new venueslistitem("sambodromo"));             items.add(new venueslistitem("maracana"));             break;         case "barra":             items.add(new venueslistheader("barra"));             items.add(new venueslistitem("olympic gold course"));             items.add(new venueslistitem("pontal"));             items.add(new venueslistitem("barra olympic park"));             items.add(new venueslistitem("riocentro"));             break;             .             .             .     }     return items; } 

despite call setlist("barra"), if click first item in list view, print 'all' not 'barra'. there way register setonitemclicklistener whenever call setadapter() ?

from codes provided, don't see have multiple implementations of onitemclicklistener. when select item in list view, log content. don't have create new adapter every time use setlist(string type). replace list arraylist items in setlist(string type) , call adapter.notifydatasetchanged() changes reflected list view.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -