android - Recyclerview touch events -
this first time working recyclerview
, have made adapter
class static mock data.
public static class viewholder extends recyclerview.viewholder{ public textview textview; public viewholder(view view){ super(view); textview = (textview)view.findviewbyid(r.id.mytextview); } } @override public viewholder oncreateviewholder(viewgroup parent, int viewtype) { view1 = layoutinflater.from(context).inflate(r.layout.item, parent ,false); toast.maketext(context, "@@@@@@@@@@@@" +viewtype, toast.length_short).show(); viewholder1 = new viewholder(view1); return viewholder1; } @override public void onbindviewholder(viewholder holder, int position) { holder.textview.settext(subjectvalues[position]); } @override public int getitemcount() { return subjectvalues.length; } }
this adapter
clas it's showing mock data want achieve click event.
inside onbindviewholder set onclicklistener
@override public void onbindviewholder(final homelistadapter.mainviewholder homeviewholder, final int position) { homeviewholder.itemview.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { toast.maketext(this, "item no: "+ position, length_short).show; } }); }
using way make items layout clickable not textview or button. if perticularly want give action on click of button or textveiew can use reference of components e.g. holder.button.setonclicklistener(new onclick..)......
Comments
Post a Comment