There is an example like that in the ApiDemos (came with SDK 1.1, not
1.5 - don't know why?). Anyway, you should download SDK 1.1 and start
ApiDemos in 1.1 emulator, and play around a little. There is a Dialog
example in com.example.android.apis.app.AlertDialogSample.java, and
here is the part of code that concerns you:

public class AlertDialogSamples extends Activity {
    private static final int DIALOG_TEXT_ENTRY = 7;

    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DIALOG_TEXT_ENTRY:
            // This example shows how to add a custom layout to an
AlertDialog
            LayoutInflater factory = LayoutInflater.from(this);
            final View textEntryView = factory.inflate
(R.layout.alert_dialog_text_entry, null);
            return new AlertDialog.Builder(AlertDialogSamples.this)
                .setIcon(R.drawable.alert_dialog_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) {

                        /* User clicked OK so do some stuff */
                    }
                })
                .setNegativeButton(R.string.alert_dialog_cancel, new
DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int
whichButton) {

                        /* User clicked cancel so do some stuff */
                    }
                })
                .create();
        }
        return null;
    }

//and here is how you show your dialog

   public boolean onMenuItemSelected(int featureId, MenuItem item) {
        switch(item.getItemId()) {
        case INSERT_ID:
            showDialog(DIALOG_TEXT_ENTRY);
            return true;
        }
        return super.onMenuItemSelected(featureId, item);
    }
} // end AlertDialogSamples

//////////////////////////////////// Here is the layout inflated into
dialog

  <?xml version="1.0" encoding="utf-8" ?>
- <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" />
  </LinearLayout>

Hope this helps!

On 18 мај, 10:35, daehoon <[email protected]> wrote:
> hi`~ all
> I want to display an messagebox when select a menu item.
> The messagebox include a string , Ok button and Cancel button
> that I can choose one.
>
>  public boolean onMenuItemSelected(int featureId, MenuItem item) {
>         switch(item.getItemId()) {
>         case INSERT_ID:
>              //
>             return true;
>         }
>         return super.onMenuItemSelected(featureId, item);
>     }

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