Tomesh Sahu Tomesh Sahu - 15 days ago 6
Android Question

How can i get the all checked radio button on a button click in a listview

i have structure like this

TextView

radio1 radio2

TextView

radio1 radio2

TextView

radio1 radio2

i want to known how can i get the all checked radio button on a button click
i tried like this

submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RadioGroup rgp;
RadioButton rbtn;
for(int i =0;i<listView.getChildCount();i++){
View layout = listView.getChildAt(i);
//int text = layout.getChildAt(1).getId();
int text = (((ViewGroup) layout).getChildAt(1)).getId();


rgp = (RadioGroup)findViewById(text);

rbtn = (RadioButton)findViewById(rgp.getCheckedRadioButtonId());
Toast.makeText(getApplicationContext(), ""+rbtn.getText().toString(),Toast.LENGTH_SHORT).show();
}

}
});

Answer