Re: [android-developers] can't access AlertDialog list items
> How can I access items I previously set using AlertDialog.Builder?
>
> private static final CharSequence[] skill_levels = { "Rookie",
> "Average", "Expert" };
>
> skillLevelBuilder = new AlertDialog.Builder( this );
> skillLevelBuilder.setTitle( "Change Skill Level" );
> skillOnClick = new DialogInterface.OnClickListener()
> {
> [...]
> }
> skillLevelBuilder.setItems( skillLevels, skillOnClick );
>
>
> I need to disable some of the items so they are visible but not
> selectable.
>
>
> I am trying (and failing) like this:
>
> AlertDialog skillLevelAlert = skillLevelBuilder.create();
> ListView lv = skillLevelAlert.getListView();
> View v = (View) lv.getItemAtPosition( 0 );
> v.setEnabled( false );
> skillLevelAlert.show();
>
> v is always null. How can I get an item to disable it?
Until the dialog is shown, the list items probably do not exist.
A cleaner implementation would be to use your own View for the innards of
the dialog, so you can tailor your own ListView and Adapter combination to
properly handle non-selectable items. For example, I do not think
setEnabled() will do what you expect. Instead, use your own ListAdapter
that implements areAllItemsEnabled() and isEnabled().
--
Mark Murphy (a Commons Guy)
http://commonsware.com
Android App Developer Books: http://commonsware.com/books.html
--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home