For those who search this group for information on this problem in the
future, I would like to both clarify the question (which some people
told me was incomprehensible) and to provide the answer to it.

So here is the situation:  I have a single-choice ListView that was
created with code similar to the following:

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_single_choice,
GENRES));

        final ListView listView = getListView();

        listView.setItemsCanFocus(false);
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    }

This creates a ListView in which every item has a radio button icon.
When the user clicks any item, the center of the radio button icon
"lights up", or becomes illuminated with a green glow, indicating that
this is the currently selected item.  As with all single-choice sets,
when one item is selected, all the others are automatically
deselected.  All well and good.  But in my application, the user has
the option of changing the order of the list by first selecting one of
the items and then clicking a Move Up or a Move Down button to move
that item up or down in the list.  The code that responds to these
clicks then rearranges the list accordingly.   But in doing so, the
original item that the user selected is no longer the current
"selected item" and no items have an illuminate radio button.  I
wanted the user to be able to see their original item with its radio
button illuminated and to make it the current "selected item".   So I
used setSelection(position) to select the proper item, thinking that
this would also cause the radio button icon to be illuminated, just as
if the user selected the item.  No such luck.  That call to
setSelection(position) does make the desired item the "selected" item
but it does cause the radio button to become illuminated.  So that was
my question.  How do I, under program control, cause a specific radio
button to become illuminated.

I hope that the question is now clear.

So what was the answer?  The answer is simple and had I not been so
impatient, I would have found it myself. Actually, I did find it
myself, but only after posting the question to this list.

The answer is:  getListView().setItemChecked(position, true);





On Apr 4, 9:48 am, DonFrench <dcfre...@gmail.com> wrote:
> Is there any way to programmatically select a ListView item such that
> when using a simple_list_item_single_choice layout, it lights up the
> radio button?  Because setSelection(position) does not seem to have
> this effect.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe, reply using "remove me" as the subject.

Reply via email to