android - RecyclerView inside of a GridView's item ruins the GridView's OnClickListener -
i have disposition of layout:
which gridview
recyclerview
s inside of each item of gridview.
i haven't found anywhere solution since think never happened before. not found in or google groups, example.
so, problem is, when set recyclerview
, method onitemclick
of gridview
doesn't called, if don't set recyclerview
gets called. these 2 codes (one setting recyclerview
, 1 hiding it):
setting recyclerview on gridview
's item
@override public view getview(int position, view convertview, viewgroup viewgroup) { viewholderitem viewholderitem; if(convertview == null) { convertview = ((layoutinflater)getactivity().getsystemservice(context.layout_inflater_service)).inflate(r.layout.item_mipeticion, viewgroup, false); viewholderitem = new viewholderitem(); viewholderitem.palabra_tv = (customtextview)convertview.findviewbyid(r.id.palabra_tv); viewholderitem.recyclerview = (recyclerview)convertview.findviewbyid(r.id.recyclerview); convertview.settag(viewholderitem); } else { viewholderitem = (viewholderitem)convertview.gettag(); } myitem item = items.get(position); string textrandom = item.gettexts().get(0); viewholderitem.palabra_tv.settext(textrandom); arraylist<drawable> drawables = item.getdrawables(); final recyclerviewimagesadapter madapter = new recyclerviewimagesadapter(drawables, getactivity()); viewholderitem.recyclerview.setlayoutmanager(new linearlayoutmanager(getactivity(), linearlayoutmanager.horizontal, false)); viewholderitem.recyclerview.setadapter(madapter); return convertview; }
this makes onclick
not getting called gridview
and code hiding it
@override public view getview(int position, view convertview, viewgroup viewgroup) { viewholderitem viewholderitem; if(convertview == null) { convertview = ((layoutinflater)getactivity().getsystemservice(context.layout_inflater_service)).inflate(r.layout.item_mipeticion, viewgroup, false); viewholderitem = new viewholderitem(); viewholderitem.palabra_tv = (customtextview)convertview.findviewbyid(r.id.palabra_tv); viewholderitem.recyclerview = (recyclerview)convertview.findviewbyid(r.id.recyclerview); convertview.settag(viewholderitem); } else { viewholderitem = (viewholderitem)convertview.gettag(); } myitem item = items.get(position); string textrandom = item.gettexts().get(0); viewholderitem.palabra_tv.settext(textrandom); arraylist<drawable> drawables = item.getdrawables(); final recyclerviewimagesadapter madapter = new recyclerviewimagesadapter(drawables, getactivity()); viewholderitem.recyclerview.setvisibility(view.gone); // not setting adapter , hidding return convertview; }
what's wrong this?
thank in advance.
regards.
rafael.
edit: i've discovered won't work
- setting
android:clickable="false"
recyclerview on xml. - handle
recyclerview
's click , callingparent.performclick()
- setting
gesturedetector
@droidekas mentioned handlesrecyclerview
's click, not whole item's click (soonitemclick
gridview
)
from understand,you want other actions apart click work on recyclerview:
you need differentiate between gestures. job gesturedetector
.so use gesturedetector.simpleongesturelistener
final gesturedetector gd = new gesturedetector(new gesturedetector.simpleongesturelistener() { @override public boolean onsingletapconfirmed(motionevent e) { //perform parent view click return true; } });
you can add recyclerview.onitemtouchlistener.
recyclerview.addonitemtouchlistener(new recyclerview.onitemtouchlistener() { @override public boolean onintercepttouchevent(recyclerview rv, motionevent e) { return gd.ontouchevent(e); } @override public void ontouchevent(recyclerview rv, motionevent e) { } @override public void onrequestdisallowintercepttouchevent(boolean disallowintercept) { } });
this make sure other touch events handled recyclerview
ps : please make sure itemview within inner recyclerview not have own click event
Comments
Post a Comment