android - Get the selected TextView value in a RecyclerView -
i trying textview
value out of selected item within recyclerview
. recyclerview
layout file has 2 textview
s, 1 name , other date can see here:
<textview android:id="@+id/layout_recyclerview_view_list_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentstart="true" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:textstyle="bold" android:textappearance="?android:attr/textappearancelarge" /> <textview android:id="@+id/layout_recyclerview_view_list_date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignstart="@+id/layout_recyclerview_view_list_name" android:layout_alignleft="@+id/layout_recyclerview_view_list_name" android:layout_below="@+id/layout_recyclerview_view_list_name" />
this adapter class recyclerview
:
list<listsrecyclerviewlist> list; public listsrecyclerviewlistadapter(list<listsrecyclerviewlist> list) { this.list = list; } @override public listsrecyclerviewlistviewholder oncreateviewholder(viewgroup parent, int viewtype) { view view = layoutinflater.from(parent.getcontext()).inflate(r.layout.layout_recyclerview_view_list, parent, false); listsrecyclerviewlistviewholder viewholder = new listsrecyclerviewlistviewholder(view); return viewholder; } @override public void onbindviewholder(listsrecyclerviewlistviewholder holder, int position) { holder.name.settext(list.get(position).getname()); holder.date.settext(list.get(position).getdate()); } @override public int getitemcount() { return list.size(); } public static class listsrecyclerviewlistviewholder extends recyclerview.viewholder { textview name; textview date; public listsrecyclerviewlistviewholder(view view) { super(view); this.name = (textview) view.findviewbyid(r.id.layout_recyclerview_view_list_name); this.date = (textview) view.findviewbyid(r.id.layout_recyclerview_view_list_date); } }
this onclick
event launches other activity mentioned earlier:
recyclerview.addonitemtouchlistener( new listsrecyclerviewlistlistener(this, new listsrecyclerviewlistlistener.onitemclicklistener() { @override public void onitemclick(view view, int position) { intent intent = new intent(getbasecontext(), listseditlistactivity.class); bundle bundle = new bundle(); bundle.putstring("name", /*this need set value*/); intent.putextras(bundle); startactivity(intent); } }) );
this class sets values list
, recyclerview
:
public string name; public string date; public listsrecyclerviewlist(string name, string date) { this.name = name; this.date = date; }
how can name field selected item within recyclerview
, pass activity? suggestions?
you can use viewholder.name.gettext(list.get(position).name)
. text textview
@ position stored in variable position
.
Comments
Post a Comment