sigmabeta
sigmabeta

Reputation: 1184

Indicating the selected item of a Single-Choice list Dialog

I have an AlertDialog that contains a ListView populated using setSingleChoiceItems. Between the user clicking on their desired item and the "OK" button, I'd like to highlight the selected item.

    builder.setSingleChoiceItems(mAdapter, -1, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Change color of clicked item
            AlertDialog alertDialog = (AlertDialog) dialog;
            alertDialog.getListView().setItemChecked(which, true);

            // Record which one was clicked
            mSelPosition = which;
        }
    })

I had thought that setItemChecked would do this, but my view does not change in any meaningful way once the user lifts their finger. Am I missing something?

Upvotes: 3

Views: 1076

Answers (1)

Kirill
Kirill

Reputation: 938

Your row view should implement the Checkable interface. And its drawable should have a layer for state_checked="true".

Upvotes: 1

Related Questions