android studio - how to get selected items in recyclerview with checkbox -


how selected items in recyclerview checkbox this example view

for example: item 1,2,3 , 4 checked. when clicked button create toast make text item selected name.

this viewholder

public class userviewgroupholder extends recyclerview.viewholder {      @bind(r.id.image_account)     circleimageview mimageaccount;     @bind(r.id.text_contact_email)     textview mtextcontactemail;     @bind(r.id.text_contact_name)     textview mtextcontactname;     @bind(r.id.check_box_user)     checkbox mcheckboxuser;      public userviewgroupholder(view itemview) {        super(itemview);        butterknife.bind(this, itemview);     }      public void bind(final account account, final user contact) {        itemview.setonclicklistener(new view.onclicklistener() {          @override         public void onclick(view v) {          }     });      mtextcontactemail.settext(contact.getemail());     mtextcontactname.settext(contact.getdisplayname());      } } 

and activity onbindviewholder

@override public void onbindviewholder(final userviewgroupholder holder, int position) {         holder.bind(maccount, musers.get(position));  } 

and activity onbindviewholder

i suppose meant adapter, not activity.

mtextcontactemail.settext(contact.getemail()); mtextcontactname.settext(contact.getdisplayname()); 

should inside bind(...)

itemview.setonclicklistener(new view.onclicklistener() {     @override     public void onclick(view v) {      } } 

must set not on itemview in holder, on "create" button in options menu. can obtain checked state of particular view few means. one* keep in user class boolean field "checked" getter/setter, , write function for loop on users list kept in adapter, returning list of users checked state "true". naturally, checked state of user have changed in bind(...).

toast names create button click easy-peasy right now: new adapter's function returns list of checked users (can return list of strings names well).

*notice, make user class mutable if immutable before.

oww , can't base checked state knowledge on holders or views, because they're reusable. if there many users (more 10), such state work on few listview items @ once, poor.


Comments