Android ListView does not respond -


i have problem listview , adapter. listview setonitemclicklistener , setonitemlongclicklistener not respond onscroll works perfectly. here code , have solution me...

thanks in advance.

public class afragment extends fragment {  view rootview; listview l; public static aarrayadapter adapter;  public afragment() { }  @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {     rootview = inflater.inflate(r.layout.fragment_list, container, false);     return rootview; }  @override public void onviewcreated(view view, bundle savedinstancestate){     l = (listview) rootview.findviewbyid(r.id.listview);      adapter = new aarrayadapter(getactivity(), r.layout.list_item_adapter, new arraylist<astring>());     l.setadapter(adapter);      l.setonitemlongclicklistener(new onitemlongclicklistener() {         public boolean onitemlongclick(adapterview<?> parent, view view, int position, long id) {             //toast doesn't work             return true;         }     });      alist();      l.setonscrolllistener(new onscrolllistener() {         private int mlastfirstvisibleitem;          @override         public void onscrollstatechanged(abslistview view, int scrollstate) {             //         }         @override         public void onscroll(abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount) {             if (mlastfirstvisibleitem < firstvisibleitem) {                 // working             }             if (mlastfirstvisibleitem > firstvisibleitem) {                 // working             }             mlastfirstvisibleitem = firstvisibleitem;         }     });     l.setonitemclicklistener(new onitemclicklistener() {          @override          public void onitemclick(adapterview<?> parent, view view, int position, long id) {              //toast doesn't work          }      }); }  public void alist(){     ... }  /***/  public class aarrayadapter extends arrayadapter<astring> {     private final context context;     private list<astring> items;      public aarrayadapter(context context, int layoutresourceid, list<astring> items) {         super(context, layoutresourceid, items);         this.context = context;         this.items = items;     }      @override     public view getview(final int position, view convertview, final viewgroup parent) {         layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);         final view rowview = inflater.inflate(r.layout.list_item_adapter, parent, false);          aholder holder = null;         holder = new aholder();         holder.acc = items.get(position);         holder.id = (textview) rowview.findviewbyid(r.id.idline);         holder.name = (textview) rowview.findviewbyid(r.id.firstline);         holder.value = (textview) rowview.findviewbyid(r.id.secondline);          rowview.settag(holder);          setupitem(holder);          final textview tvid = (textview) rowview.findviewbyid(r.id.idline);         final imagebutton imagebutton = (imagebutton) rowview.findviewbyid(r.id.icon);          return rowview;     }      private void setupitem(accholder holder) {         holder.name.settext(holder.acc.getname());         holder.value.settext(holder.acc.getvalue());         holder.id.settext(string.valueof(holder.acc.getid()));         holder.removebutton = (imagebutton) rowview.findviewbyid(r.id.icon);         holder.removebutton.settag(holder.account);          holder.removebutton.setfocusable(false); // <=========== :)     }      public class aholder {         astring account;         textview id;         textview name;         textview value;     } } } 

this possibly duplicate of - listview items not clickable. why?

to solve problem must not have focusable items inside listview/gridview.

so buttons/imagebuttons must set:

android:focusable="false"  

if have imagebutton inside listview/gridview can switch imageview button not clickable anyway , way not need change focusability.

also fpr0001 stated in link provided do:

this answer here worked me: https://stackoverflow.com/a/16536355/5112161

mainly added in linearlayout or relativelayout following:

android:descendantfocusability="blocksdescendants" 

you need remove xml following:

android:focusable="false" android:focusable="true" android:clickable="true" android:clickable="false" 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -