This works for me for an EditText as well. But when I try the same
code for a Spinner I receive a NullPointerException. Both views are in
the same Layout and both views have got an id. Actually, it is exactly
the same code except the kind of the view. Any idea why I got this
exception?

Thanks


On 24 Jul., 23:08, Jason Van Anden <jason.van.an...@gmail.com> wrote:
> That was it.
>
> Hopefully this post will help others.  I could not find a good example of
> using AlertDialog for text input.  The API Demos example does not show how
> to return the text!
>
> Thanks again Mark!
>
> Jason Van Anden
>
> On Fri, Jul 24, 2009 at 4:55 PM, Mark Murphy <mmur...@commonsware.com>wrote:
>
>
>
>
>
> > Jason Van Anden wrote:
> > > I am having a problem using AlertDialog for input text.
>
> > > Code follows ... everything appears on screen as it should until I click
> > > OK - then I get a force close.
>
> > > I get a null error on line where Editable e = et.getText();.
>
> > > Second set of eyes and a sturdy brain appreciated...
>
> > >     private void enter_search(){
>
> > >         LayoutInflater factory = LayoutInflater.from(this);
> > >         final View textEntryView =
> > > factory.inflate(R.layout.search_dialog, null);
>
> > >         new AlertDialog.Builder(Peeps.this)
>
> > >              //.setIcon(R.drawable.alert_dialog_icon)
> > >             .setTitle(R.string.search_dialog_text_entry)
> > >             .setView(textEntryView)
> > >             .setPositiveButton(R.string.search_dialog_ok, new
> > > DialogInterface.OnClickListener() {
>
> > >                 public void onClick(DialogInterface dialog, int
> > > whichButton) {
>
> > >                     EditText et =
> > > (EditText)findViewById(R.id.search_edit);   // !!! apparently I am doing
> > > this wrong!
>
> > I am assuming R.id.search_edit is a field in the textEntryView you
> > supplied to the builder.
>
> > In that case, try textEntryView.findViewById(R.id.search_edit).
>
> > --
> > Mark Murphy (a Commons Guy)
> >http://commonsware.com|http://twitter.com/commonsguy
>
> > _Android Programming Tutorials_ Version 1.0 In Print!

--~--~---------~--~----~------------~-------~--~----~
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