Dialog layout : Dialog « UI « Android






Dialog layout

  

package app.test;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Test extends Activity {
  private static final int DIALOG1 = 1;
  private static final int DIALOG2 = 2;
  private static final int DIALOG4 = 4;
  private static final int DIALOG3 = 3;


  @Override
  protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG1:
      return buildDialog1(Test.this);

    case DIALOG2:
      return buildDialog2(Test.this);

    case DIALOG3:
      return buildDialog3(Test.this);
    case DIALOG4:
      return buildDialog4(Test.this);

    }
    return null;
  }
  
  protected void onPrepareDialog(int id, Dialog dialog){
    if(id==DIALOG1){
      setTitle("5");
    }
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.row);

    Button button1 = (Button) findViewById(R.id.button1);
    button1.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
        showDialog(DIALOG1);
      }
    });

    Button buttons2 = (Button) findViewById(R.id.buttons2);
    buttons2.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
        showDialog(DIALOG2);
      }
    });

    Button button3 = (Button) findViewById(R.id.button3);
    button3.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
        showDialog(DIALOG3);
      }
    });
    
    Button button4 = (Button) findViewById(R.id.button4);
    button4.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
        showDialog(DIALOG4);
      }
    });
  }

  private Dialog buildDialog1(Context context) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setIcon(R.drawable.icon);
    builder.setTitle("asdf");
    builder.setPositiveButton("OK",
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            setTitle("1");
          }
        });
    builder.setNegativeButton("Cancel",
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {

            setTitle("2");
          }
        });
    return builder.create();

  }
  private Dialog buildDialog2(Context context) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setIcon(R.drawable.icon);
    builder.setTitle("asdf");
    builder.setMessage("asdf");
    builder.setPositiveButton("Ok",
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {

            setTitle("OK");
          }
        });
    builder.setNeutralButton("OK 2",
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {

            setTitle("title 2");
          }
        });
    builder.setNegativeButton("Cancel",
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {

            setTitle("cancel");
          }
        });
    return builder.create();
  }

  private Dialog buildDialog3(Context context) {
    LayoutInflater inflater = LayoutInflater.from(this);
    final View textEntryView = inflater.inflate(
        R.layout.add_edit, null);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setIcon(R.drawable.icon);
    builder.setTitle("text_entry");
    builder.setView(textEntryView);
    builder.setPositiveButton("OK",
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            setTitle("3");
          }
        });
    builder.setNegativeButton("Cancel",
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            setTitle("4");
          }
        });
    return builder.create();
  }
  

  private Dialog buildDialog4(Context context) {
    ProgressDialog dialog = new ProgressDialog(context);
    dialog.setTitle("4");
    dialog.setMessage("4");
    return  dialog;
  }
}

//main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
</LinearLayout>


//row.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/screen" android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:orientation="vertical">
  <LinearLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical">
    <Button android:id="@+id/button1"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" android:text="1" />
    <Button android:id="@+id/buttons2"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" android:text="2" />
    <Button android:id="@+id/button3"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" android:text="3" />
    <Button android:id="@+id/button4"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" android:text="4" />
  </LinearLayout>
</ScrollView>

//add_edit.xml

<?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="UserName"
    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:capitalize="none"
    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="Password"
    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:capitalize="none"
    android:password="true"
    android:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>

   
    
  








Related examples in the same category

1.Dialog Helper
2.Use AlertDialog to inform exception
3.Add option item to Alert dialog and get user selection result
4.Add some padding to keep the dialog borders away
5.Dialog activity and TextView
6.Preference dialog
7.Show dialog
8.Layout dialog with xml layout file
9.extends DialogFragment
10.Color Picker Dialog
11.Dialog Yes No Message
12.Dialog Yes No Old School Message
13.Dialog Yes No Holo Light Message
14.Dialog Yes No Long Message
15.Dialog Yes No Ultra Long Message
16.Dialog with List of value
17.Dialog with Progress
18.Dialog with Single Choice
19.Dialog Multiple Choice
20.Dialog Multiple Choice Cursor
21.Dialog with Text Entry
22.Dialog with Xml layout
23.Dialog Activity
24.Demonstrates how to show an AlertDialog that is managed by a Fragment.
25.Fragment Dialog
26.Demonstrates the use of progress dialogs.
27.File open dialog
28.Show error AlertDialog
29.extends DialogPreference
30.Show Notification Alert Dialog
31.Text Dialog
32.Create Chang Log Dialog
33.Show Title And Message Dialog
34.Show dialog and parse URL
35.Error Dialog Wrapper
36.Ok Dialog Wrapper
37.Display an alert dialog
38.AlertDialog Question
39.import android.app.AlertDialog;
40.dialog Builder
41.A dialog that allows the user to select multiple entries.
42.Help Dialog Creator
43.Color Select Dialog
44.Create MessageBox