android - Why is created a RadioGroup duplicate object in my RecyclerView.ViewHolder? -


i have recyclerview several viewholder , viewholder specify radiogroup creating alternately 2 radiogrouds objects memory reference, when check 1 other checked too:

my recyclerview.adapter:

private class questionadapter extends recyclerview.adapter<recyclerview.viewholder> {     private list<question> mquestions;     private final int simple = 0;     private final int binary = 2;     private final int options = 3;     private final int checkbox = 5;      public questionadapter(list<question> questions) {         this.mquestions = questions;     }      @override     public recyclerview.viewholder oncreateviewholder(viewgroup parent, int viewtype) {         recyclerview.viewholder viewholder = null;         layoutinflater inflater = layoutinflater.from(parent.getcontext());          switch (viewtype) {             case simple:                 view view = inflater.inflate(r.layout.question_simple_cell, parent, false);                 viewholder = new questionsimpleholder(view);                 break;             case binary:                 view view2 = inflater.inflate(r.layout.question_binary_cell, parent, false);                 viewholder = new questionbinaryholder(view2);                 break;             case checkbox:                 view view4 = inflater.inflate(r.layout.question_check_cell, parent, false);                 viewholder = new questioncheckholder(view4);                 break;             case options:                 view view1 = inflater.inflate(r.layout.question_with_options, parent, false);                 viewholder = new questionoptionsholder(view1);                 break;         }         return viewholder;     }      @override     public void onbindviewholder(recyclerview.viewholder holder, int position) {          switch (holder.getitemviewtype()) {             case simple:                 question question = this.mquestions.get(position);                 questionsimpleholder simpleholder = (questionsimpleholder) holder;                 simpleholder.bindquestion(question);                 break;             case binary:                 question question2 = this.mquestions.get(position);                 questionbinaryholder binaryholder = (questionbinaryholder) holder;                 binaryholder.bindquestion(question2);                 break;             case checkbox:                 question question4 = this.mquestions.get(position);                 questioncheckholder checkholder = (questioncheckholder) holder;                 checkholder.bindquestion(question4);                 break;             case options:                 question question1 = this.mquestions.get(position);                 questionoptionsholder optionsholder = (questionoptionsholder) holder;                 optionsholder.bindquestion(question1);                 break;         }     }      @override     public int getitemviewtype(int position) {         int type = this.mquestions.get(position).gettype();         switch (type) {             case 2:                 return binary;             case 3:                 return options;             case 5:                 return checkbox;             default:                 return simple;         }     }      @override     public int getitemcount() {         return this.mquestions.size();     } } 

my viewholder:

private class questionbinaryholder extends recyclerview.viewholder {     private textview mtextview;     private question mquestion;     private radiogroup mradiogroup;     private radiobutton mradiobutton1;     private radiobutton mradiobutton0;      public questionbinaryholder(view itemview) {         super(itemview);         mtextview = (textview) itemview.findviewbyid(r.id.text_title_question);         mradiogroup = (radiogroup) itemview.findviewbyid(r.id.radio_binary);         mradiobutton0 = (radiobutton) itemview.findviewbyid(r.id.radio_0);         mradiobutton1 = (radiobutton) itemview.findviewbyid(r.id.radio_1);      }      public void bindquestion(question question) {         mquestion = question;         mtextview.settext(mquestion.gettitle());          mradiobutton0.settext(question.getoptions().get(1));         mradiobutton1.settext(question.getoptions().get(0));          mradiogroup.setoncheckedchangelistener(new radiogroup.oncheckedchangelistener() {             @override             public void oncheckedchanged(radiogroup radiogroup, int i) {                 radiobutton radiobutton = (radiobutton) radiogroup.findviewbyid(i);                 //showquestion(radiobutton.gettext());                 log.d(tag, string.valueof(radiogroup));             }         });     } } 


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -