views:

27

answers:

1

Hi! I have a radiobutton group in Android that I populate with data from a database. To get the data to show next to each radiobutton I have used the ListAdapter:

String[] columns = new String[] {DataHelper.KEY_WORD, DataHelper.KEY_ALT1 , DataHelper.KEY_ALT2 ,DataHelper.KEY_ALT3 ,DataHelper.KEY_ALT4 };
            // the XML defined views which the data will be bound to
            int[] to = new int[] { R.id.word, R.id.q1, R.id.q2, R.id.q3 , R.id.q4 };

SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.game, c, columns, to);
this.setListAdapter(mAdapter);

In order to get the ListAdapter to work I need a listview, but the listview seems to disable my OnClickListener.

How could I solve this? Is there anyway to not use a listview to populate the radiogroup, or a way to keep the onClickLIsteners active inside it?

A: 

You have to use checkbox/radiobutton mechanism provided by Android ListView. You cannot implement click listeners yourself inside ListView.

Take a look at ListView.getCheckedItemPosition to get started: http://developer.android.com/reference/android/widget/ListView.html#getCheckedItemPosition()

Juhani
Hi, and thanks for the response. I have tried now to add ListView lv = this.getListView(); this.getListAdapter(); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); lv.setItemsCanFocus(true); lv.setOnClickListener(rq_listener); is this a right way to think? the rq_listener is the one I used for the radiobuttons before i imported data from a database, and when I add it to the setOnClickListener the activity won't launch.
Anna-Karin
I don't think I have understood how I need to think, should all actions be "on" the listview and then get passed to the radiobuttons? How can I use the result returned from GetItemCheckedPosition? Sorry for the many questions, am a newbie!
Anna-Karin