I also had to do one of the following to get it to work correctly.

    if (!lv.isItemChecked(0)) {
        lv.setItemChecked(0, true);
    }

or

    lv.clearChoices();
    lv.setItemChecked(0, true);


On Mar 27, 11:17 pm, Glen Humphrey <glendon.humphr...@gmail.com>
wrote:
> This seems to work for me. I have not been able to find a constant in
> the SDK for 16908667.  I will keep looking.
>
>                  AlertDialog ad = (AlertDialog) d;
>                  ListView lv = (ListView) ad.findViewById(16908667);
>                  lv.setItemChecked(0, true);
>
> On Mar 27, 6:15 pm, Brian <hibr...@gmail.com> wrote:
>
> > That returns null... Specifically:
>
> > protected void onPrepareDialog(int id, Dialog d){
> > super.onPrepareDialog(id, d);
> > ListView lv = (ListView) d.findViewById(android.R.id.list);
> > // lv is null
> > ...
>
> > }
>
> > The dialog is created by:
> > new AlertDialog.Builder(...)
> >             .setIcon(...)
> >             .setTitle(...)
> >             .setSingleChoiceItems(R.array.dialog_items, 0, new
> > DialogInterface.OnClickListener() {
> >                 public void onClick(DialogInterface dialog, int
> > whichButton) {
> > ...
> >                 }
> >             })
> >             more stuff
> >             .create();
>
> > The dialog is shown by a call to: showDialog(1);
>
> > On Mar 27, 6:58 pm, Glen Humphrey <glendon.humphr...@gmail.com> wrote:
>
> > > I think you do something like this in the onPrepareDialog method.
>
> > > ListView listView = (ListView) dialog.findViewById(android.R.id.list);
> > > listView.setItemChecked(0, true);
>
> > > On Mar 27, 9:42 am, Brian <hibr...@gmail.com> wrote:
>
> > > > How do you set the checked item of a single choice dialog, after the
> > > > dialog has been created?
> > > > Subsequent calls to showDialog() seem to remember and display the
> > > > user's last checked item.  I want to set the checked item myself, each
> > > > time the dialog is displayed.
>
> > > > Is there some way to set the selected item in onPrepareDialog() or
> > > > elsewhere?
>
> > > > Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to