android - Can't catch touch event of Child View of Header of Sticky Header (RecyclerView) by eowise -
i'm using library "recyclerview-stickyheaders" link here : https://github.com/eowise/recyclerview-stickyheaders ok, can't catch touch event .setonheaderclicklistener(this) use stickyheadersbuilder class. can't , don't know how implement click listener child view of "header" ( textview, button in header ), in case btnfollow. catch touch event whole "header". try implement click listener class viewholder of header on ( headeradapter ) doesn't work. * in mainactivity :
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); recyclerview = (recyclerview) findviewbyid(r.id.rv_timeline); adapterrecyclerview = new adapterrecyclertimeline(getapplicationcontext(), getdata()); adapterrecyclerview.setclicklistener(this); recyclerview.setlayoutmanager(new linearlayoutmanager(getapplicationcontext())); recyclerview.setitemanimator(new defaultitemanimator()); adapterheader = new adaptertimelineheader(getapplicationcontext(), getdata()); adapterheader.setclicklistener(this); recyclerheader = new stickyheadersbuilder() .setadapter(adapterrecyclerview) .setrecyclerview(recyclerview) .setstickyheadersadapter(adapterheader) .setonheaderclicklistener(this) .build(); recyclerview.setadapter(adapterrecyclerview); recyclerview.additemdecoration(recyclerheader); } @override public void onheaderclick(view header, long headerid) { toast.maketext(getapplicationcontext(), "header clicked lib", toast.length_short).show(); } @override public void headerclicked(view view, int position) { toast.maketext(getapplicationcontext(), "header clicked manual", toast.length_short).show(); }
in adapterheader
public class viewholder extends recyclerview.viewholder implements view.onclicklistener{ relativelayout profile; textview tvprofilename; textview btnfollow;
public viewholder(view itemview) { super(itemview); profile = (relativelayout) itemview.findviewbyid(r.id.profile); tvprofilename = (textview) itemview.findviewbyid(r.id.tv_profile_name); btnfollow = (textview) itemview.findviewbyid(r.id.btn_follow); btnfollow.setonclicklistener(this); l.m("set listener follow"); } @override public void onclick(view v) { if (clicklistener != null) { l.m("do click follow"); clicklistener.headerclicked(v, getposition()); } }
} public interface clicklistener { public void headerclicked(view view, int position); }
public void setclicklistener(clicklistener clicklistener) { this.clicklistener = clicklistener; }
thank all!
this libraries not add view screen - copies pixel pixel view canvas. here code:
```
canvas.save(); canvas.translate(0, y); header.draw(canvas); canvas.restore();
```
so header not on screen - it`s visual clone.
it possible handle clicks on parent view - see library (it looks practically same)
but parent view extremely difficult send click event child (for example buttons in). , of course no animation because see not view.
Comments
Post a Comment