Finally I resolved this problem by invoking the flattened view's
findViewById(), hope this can be helpful for others.

On Apr 15, 5:20 pm, Bin Chen <binary.c...@gmail.com> wrote:
> It's weird, if I change the code into:
>
>                                                         new 
> DialogInterface.OnClickListener() {
>                                                                 public void 
> onClick(DialogInterface dialog,
>                                                                               
>   int whichButton) {
>                                                                         
> String user;
>                                                                         
> String password;
>
>                                                                         
> setContentView(R.layout.alert_dialog_text_entry);
>                                                                         
> EditText user_edit = (EditText)findViewById
> (R.id.username_edit);
>                                                                         
> EditText password_edit = (EditText)findViewById
> (R.id.password_edit);
>                                                                         user 
> = user_edit.getText().toString();
>                                                                         
> setContentView(R.layout.main);
>                                                                 }
>
> Then the button in the main view has no effect at all, is it a bug? Or
> the way I do is wrong?
>
> On Apr 15, 5:16 pm, Bin Chen <binary.c...@gmail.com> wrote:
>
> > Sovled by adding a setContentView()...
>
> > On Apr 15, 5:10 pm, Bin Chen <binary.c...@gmail.com> wrote:
>
> > > I have a main.xml as the main view and another
> > > alert_dialog_text_entry.xml for one dialog when a button is clicked in
> > > the main.xml view. In the click handler of the button, the findViewById
> > > () can't work, the returned vaule is null, the code is like this:
>
> > >         protected Dialog onCreateDialog(int id) {
> > >                 switch (id) {
> > >                 case DIALOG_ACCOUNT_SETTING:
> > >                         LayoutInflater factory = 
> > > LayoutInflater.from(mymsn.GetContext());
> > >                         View textEntryView = factory.inflate(
> > >                                         R.layout.alert_dialog_text_entry, 
> > > null);
> > >                         return new AlertDialog.Builder(this)
> > >                                         .setIcon(R.drawable.icon)
> > >                                         
> > > .setTitle(R.string.alert_dialog_text_entry)
> > >                                         .setView(textEntryView)
> > >                                         
> > > .setPositiveButton(R.string.alert_dialog_ok,
> > >                                                         new 
> > > DialogInterface.OnClickListener() {
> > >                                                                 public 
> > > void onClick(DialogInterface dialog,
> > >                                                                           
> > >       int whichButton) {
> > >                                                                         
> > > String user;
> > >                                                                         
> > > String password;
>
> > >                                                                         
> > > EditText user_edit = (EditText)findViewById
> > > (R.id.username_edit);
> > >                                                                         
> > > EditText password_edit = (EditText)findViewById
> > > (R.id.password_edit);
> > >                                                                         
> > > user = user_edit.getText().toString();
>
> > >                                                                 }
> > >                                                         })
> > >                                         
> > > .setNegativeButton(R.string.alert_dialog_cancel,
> > >                                                         new 
> > > DialogInterface.OnClickListener() {
> > >                                                                 public 
> > > void onClick(DialogInterface dialog,
> > >                                                                           
> > >       int whichButton) {
> > >                                                                 }
> > >                                                         })
> > >                                         .create();
> > >                 }
>
> > > The alert_dialog_text_entry.xml:
>
> > > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> > > android"
> > >     android:layout_width="fill_parent"
> > >     android:layout_height="wrap_content"
> > >     android:orientation="vertical">
>
> > >     <TextView
> > >         android:id="@+id/username_view"
> > >         android:layout_height="wrap_content"
> > >         android:layout_width="wrap_content"
> > >         android:layout_marginLeft="20dip"
> > >         android:layout_marginRight="20dip"
> > >         android:text="@string/alert_dialog_username"
> > >         android:gravity="left"
> > >         android:textAppearance="?android:attr/textAppearanceMedium" />
>
> > >     <EditText
> > >         android:id="@+id/username_edit"
> > >         android:layout_height="wrap_content"
> > >         android:layout_width="fill_parent"
> > >         android:layout_marginLeft="20dip"
> > >         android:layout_marginRight="20dip"
> > >         android:scrollHorizontally="true"
> > >         android:autoText="false"
> > >         android:capitalize="none"
> > >         android:gravity="fill_horizontal"
> > >         android:textAppearance="?android:attr/textAppearanceMedium" />
>
> > >     <TextView
> > >         android:id="@+id/password_view"
> > >         android:layout_height="wrap_content"
> > >         android:layout_width="wrap_content"
> > >         android:layout_marginLeft="20dip"
> > >         android:layout_marginRight="20dip"
> > >         android:text="@string/alert_dialog_password"
> > >         android:gravity="left"
> > >         android:textAppearance="?android:attr/textAppearanceMedium" />
>
> > >     <EditText
> > >         android:id="@+id/password_edit"
> > >         android:layout_height="wrap_content"
> > >         android:layout_width="fill_parent"
> > >         android:layout_marginLeft="20dip"
> > >         android:layout_marginRight="20dip"
> > >         android:scrollHorizontally="true"
> > >         android:autoText="false"
> > >         android:capitalize="none"
> > >         android:gravity="fill_horizontal"
> > >         android:password="true"
> > >         android:textAppearance="?android:attr/textAppearanceMedium" />
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to