How to create and show dialog in the android application?
<p>Good evening, programmers. I have a problem. Please help me to solve it.
I am writing an android application. I can't create custom dialogs. I have errors or my application looks very awfully. I have some dialogs in my application. Here is of a part of my programm:</p>

<p>The view is very terrible, isn't it? <strong>I want that one of the layouts to be in the dialog</strong> but it appears in the main activity. Why?</p>

<p><strong>dialogtable.xml</strong></p>

<pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/LinearLayout01"
 android:orientation="vertical"
 android:layout_height="fill_parent"
 android:layout_width="fill_parent"
 &gt;
  &lt;LinearLayout
   android:id="@+id/LinearLayout02"
   android:orientation="horizontal"
   android:layout_height="fill_parent"
   android:layout_width="fill_parent"
   &gt;

   &lt;TextView
    android:id="@+id/textRows"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="left"
    android:text="Amount of rows "/&gt;

   &lt;TextView
    android:id="@+id/textColumns"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="right"
    android:text="Amount of columns"/&gt;

  &lt;/LinearLayout&gt;

  &lt;LinearLayout 
   android:id="@+id/LinearLayout03"
   android:orientation="horizontal"
   android:layout_height="wrap_content"
   android:layout_width="wrap_content"
   &gt;

   &lt;EditText
    android:id="@+id/EditText01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:inputType="number"
    android:gravity="right"/&gt;


   &lt;EditText
    android:id="@+id/EditText02"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="right"/&gt;

  &lt;/LinearLayout&gt;

  &lt;LinearLayout 
   android:id="@+id/LinearLayout04"
   android:orientation="vertical"
   android:layout_height="wrap_content"
   android:layout_width="wrap_content"
   &gt;

  &lt;TextView
    android:id="@+id/textBorder"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="right"
    android:text="Width of border"/&gt;

  &lt;EditText
    android:id="@+id/EditText03"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="right"/&gt;

  &lt;/LinearLayout&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>The code from MainActivity</p>

<pre><code>@Override
protected Dialog onCreateDialog(int id) {
    LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);

    View layout = inflater.inflate(R.layout.dialogtable, (ViewGroup)findViewById(R.id.LinearLayout01));

    AlertDialog.Builder alert = null;
    alert = new AlertDialog.Builder(this);
    alert.setView(layout);
    alert.setTitle("Create table");
    alert.setCancelable(false);
    alert.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {

        @Override
            public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    alert.setPositiveButton("OK",new DialogInterface.OnClickListener() {

        @Override
            public void onClick(DialogInterface dialog, int which) {

            Editable rows = fieldForRows.getText();
            Editable columns = fieldForColumns.getText();
            Editable border = fieldForWidthOfBroder.getText();


            TableAction tableAction = new TableAction(MainActivity.this.visualPane);
            tableAction.insertTable(rows, columns, border);
        }
    });
    Dialog dialog = null;
    dialog = new Dialog(this);
    switch (id) {
    case IDD_CUSTOM_INSERT_TABLE:
        dialog.setTitle("Insert table");
        dialog.setContentView(R.layout.dialogtable);
        return dialog;
    case IDD_CUSTOM_INSERT_IMAGE:
        dialog.setTitle("Insert image");
        return dialog;
    default:
        return alert.create();
    }
}
</code></pre>

<p>The appearance of the application before calling showDialog():</p>

<p><a href="http://s015.radikal.ru/i330/1101/d0/f7cc38852dc6.jpg" rel="nofollow">http://s015.radikal.ru/i330/1101/d0/f7cc38852dc6.jpg</a></p>

<p>The appearance of the application after calling showDialog():</p>

<p><a href="http://s003.radikal.ru/i201/1101/f0/d1ebc436427f.jpg" rel="nofollow">http://s003.radikal.ru/i201/1101/f0/d1ebc436427f.jpg</a></p>

<p>Why it looks so terrible? What is wrong?</p>
