As simple as this seems I have not been able to find an easy way solution to this, I have a simple radio button list view and I want to extract the value of the radio button selected on button click event.
Here is the code you might have seen in a million other places.
public class RadioListActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>this,android.R.layout.simple_list_item_single_choice, CONTENT));
final ListView listView = getListView();
listView.setItemsCanFocus(false);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
private static final String[] CONTENT = new String[] {"bla1","bla2","bla3","bla4","bla5"};
}
ANY help is appreciated! :]
The answer lies in two simple lines of codes which I had to scavenge for days at end.
Just adding the below two lines to the onClick event will extract the index of the item selected along with the value at it!
ListView l=getListView();
Object obj=l.getItemAtPosition(l.getCheckedItemPosition());
Hope someone finds the above helpful. Cheers!