Checkbox enable EditText in RecyclerView issue -


i working quiz app project. i've got recyclerview, each of them contains textview, 2 checkbox , edittext. want when checked second checkbox enable edittext. have make work. problem if checked checkbox , type in edittext on first row, when scroll down of others mirroring edittext state not checked checkbox enable edittext of row.

here adapter code:

    public class studentadapter extends recyclerview.adapter<studentadapter.studentviewholder> {      private layoutinflater inflator;     private int status;     typeface typeface;      list<student> students = collections.emptylist();      public studentadapter(context context, list<student> students, string font) {          inflator = layoutinflater.from(context);         this.students = students;         typeface = typeface.createfromasset(context.getassets(), font);      }       @override     public studentviewholder oncreateviewholder(viewgroup parent, int viewtype) {          view view = inflator.inflate(r.layout.student_row, parent, false);          studentviewholder studentviewholder = new studentviewholder(view);           return studentviewholder;     }      @override     public void onbindviewholder(final studentviewholder holder, final int position) {          final student currentstudent = students.get(position);         holder.studentname.settext(currentstudent.student);         holder.chbillegal.settag(students.get(position));         holder.edittext.settag(students.get(position));          holder.chbillegal.setchecked(students.get(position).isselected());           holder.chbillegal.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                  checkbox cb = (checkbox) v;                  final student contact = (student) cb.gettag();                  contact.setselected(cb.ischecked());                 students.get(position).setselected(cb.ischecked());                // enable edittext if checkbox checked                 if (cb.ischecked()) {                     holder.edittext.setenabled(true);                      holder.edittext.addtextchangedlistener(new textwatcher() {                         @override                         public void beforetextchanged(charsequence s, int start, int count, int after) {                          }                          @override                         public void ontextchanged(charsequence s, int start, int before, int count) {                          }                          @override                         public void aftertextchanged(editable s) {                               string illegal = holder.edittext.gettext().tostring();                             contact.setagaints_rule(illegal);                             log.d("gexam", currentstudent.student + " " + illegal);                           }                     });                      holder.chbillegal.setonclicklistener(null);                     holder.chbillegal.settag(students.get(position));                   } else {                      holder.edittext.setenabled(false);                 }               }         });           if (currentstudent.getstatus() == 1) {               holder.chbpresent.setchecked(true);           } else if (currentstudent.getstatus() == 0) {              holder.chbpresent.setchecked(false);          }       }      @override     public int getitemcount() {         return students.size();     }       class studentviewholder extends recyclerview.viewholder {           textview studentname;         checkbox chbpresent, chbillegal;         edittext edittext;          public studentviewholder(view itemview) {              super(itemview);              studentname = (textview) itemview.findviewbyid(r.id.studentlisttext);              this.studentname.settypeface(typeface);              edittext = (edittext) itemview.findviewbyid(r.id.edtagaintsrule);             chbpresent = (checkbox) itemview.findviewbyid(r.id.chbpresent);              // chbillegal handle edittext             chbillegal = (checkbox) itemview.findviewbyid(r.id.chbillegal);              edittext.setenabled(false);           }     }      public list<student> getstudentlist() {          return students;      } } 

how can enable edittext of row checkbox checked?

finally i've been able solve problem teacher helped. have changed move listener onbindviewholder viewholder class this:

public class studentadapter extends recyclerview.adapter<studentadapter.studentviewholder> {      private layoutinflater inflator;     private int status;     typeface typeface;      list<student> students = collections.emptylist();      public studentadapter(context context, list<student> students, string font) {          inflator = layoutinflater.from(context);         this.students = students;         typeface = typeface.createfromasset(context.getassets(), font);      }       @override     public studentviewholder oncreateviewholder(viewgroup parent, int viewtype) {          view view = inflator.inflate(r.layout.student_row, parent, false);          studentviewholder studentviewholder = new studentviewholder(view);           return studentviewholder;     }      @override     public void onbindviewholder(final studentviewholder holder, final int position) {              final student currentstudent = students.get(position);         holder.studentname.settext(currentstudent.student);         holder.chbillegal.settag(students.get(position));         holder.edittext.settag(students.get(position));   holder.edittext.settext(currentstudent.getagaints_rule());          if (currentstudent.isselected()) {             holder.edittext.setenabled(true);         }else{             holder.edittext.setenabled(false);         }         holder.chbillegal.setchecked(students.get(position).isselected());           if (currentstudent.getstatus() == 1) {               holder.chbpresent.setchecked(true);            } else if (currentstudent.getstatus() == 0) {              holder.chbpresent.setchecked(false);          }       }      @override     public int getitemcount() {         return students.size();     }       class studentviewholder extends recyclerview.viewholder {           textview studentname;         checkbox chbpresent, chbillegal;         edittext edittext;          public studentviewholder(view itemview) {              super(itemview);              studentname = (textview) itemview.findviewbyid(r.id.studentlisttext);              this.studentname.settypeface(typeface);              edittext = (edittext) itemview.findviewbyid(r.id.edtagaintsrule);             chbpresent = (checkbox) itemview.findviewbyid(r.id.chbpresent);             chbillegal = (checkbox) itemview.findviewbyid(r.id.chbillegal);              chbillegal.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view v) {                      checkbox cb = (checkbox) v;                     student s = (student) v.gettag();                     log.e("gexam", string.valueof(cb.ischecked()));                     s.setselected(cb.ischecked());                     studentviewholder.this.edittext.setenabled(cb.ischecked());                  }             });              edittext.addtextchangedlistener(new textwatcher() {                         @override                         public void beforetextchanged(charsequence s, int start, int count, int after) {                          }                          @override                         public void ontextchanged(charsequence s, int start, int before, int count) {                          }                          @override                         public void aftertextchanged(editable s) {                              student student = (student) studentviewholder.this.edittext.gettag();                             student.setagaints_rule(s.tostring());                         }                     });            }     }      public list<student> getstudentlist() {          return students;      } } 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -