How To Select Multiple Radiobuttons In Listview And Arranging In Arraylist Using Their Positions
Iam having 25 questions with each having 4 options(nothing but 4 radio buttons) selecting on among the four in listview.Iam getting selected position and their radio id accurately
Solution 1:
try this code it is working 1.i have taken one bean class with string and integer as fields i am creating one arraylist with type as bean 2. in the onCreate i am creating objects and setting the requid question and ADD to list // here is adapter code
@Overridepublic View getView(int position, View convertView, ViewGroup parent) {
ViewHolder mHolder;
// if (convertView == null) {
mHolder = newViewHolder();
convertView = LayoutInflater.from(mContext).inflate(R.layout.listitems, null);
mHolder.mTextView = (TextView) convertView.findViewById(R.id.textView1);
mHolder.mGroup = (RadioGroup) convertView.findViewById(R.id.radioGroup1);
mHolder.mRedButton1 = (RadioButton) convertView.findViewById(R.id.radio0);
mHolder.mRedButton2 = (RadioButton) convertView.findViewById(R.id.radio1);
mHolder.mRedButton3 = (RadioButton) convertView.findViewById(R.id.radio2);
// convertView.setTag(mHolder);// }// else {// mHolder = (ViewHolder) convertView.getTag();// }finalMyQuestionmMyQuestion= myQuestions.get(position);
mHolder.mTextView.setText(mMyQuestion.getmQuestion());
intmQuestion_answed= mMyQuestion.getQuestion_answed();
mHolder.mGroup.setOnCheckedChangeListener(null);
if (mQuestion_answed != 0) {
switch (mQuestion_answed) {
case1:
mHolder.mRedButton1.setChecked(true);
break;
case2:
mHolder.mRedButton2.setChecked(true);
break;
case3:
mHolder.mRedButton3.setChecked(true);
break;
default:
break;
}
}
// listener for radioGroup
mHolder.mGroup.setOnCheckedChangeListener(newOnCheckedChangeListener() {
@OverridepublicvoidonCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.radio0:
mMyQuestion.setQuestion_answed(1);
break;
case R.id.radio1:
mMyQuestion.setQuestion_answed(2);
break;
case R.id.radio2:
mMyQuestion.setQuestion_answed(3);
break;
default:
break;
}
}
});
return convertView;
}
// VIewHolder
privateclassViewHolder {
TextView mTextView;
RadioGroup mGroup;
RadioButton mRedButton1, mRedButton2, mRedButton3;
}
// bean class
publicclassMyQuestion {
privateString mQuestion;
private int question_answed;
publicMyQuestion() {
super();
}
publicStringgetmQuestion() {
return mQuestion;
}
publicvoidsetmQuestion(String mQuestion) {
this.mQuestion = mQuestion;
}
public int getQuestion_answed() {
return question_answed;
}
publicvoidsetQuestion_answed(int question_answed) {
this.question_answed = question_answed;
}
}
this is the ArrayList i am using
privateArrayList<MyQuestion> mQuestionsList = new ArrayList<MyQuestion>();
Post a Comment for "How To Select Multiple Radiobuttons In Listview And Arranging In Arraylist Using Their Positions"