Sovled by adding a setContentView()...

On Apr 15, 5:10 pm, Bin Chen <[email protected]> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to