2011-02-05 5 views
3

AlertDialogが送信ボタンを表示していません。以下はコードです。私のコードで間違いを犯したことを教えてください。あなたが二回正ボタンを設定AlertDialogが2つのボタンを表示していない

protected Dialog onCreateDialog(int id) { 
    final AlertDialog.Builder dialog = new AlertDialog.Builder(this); 
    dialog.setMessage("Enter Holla message"); 
    EditText hollaMessage = new EditText(this); 
    dialog.setView(hollaMessage); 
    dialog.setCancelable(false); 
    dialog.setPositiveButton("Send", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int id) { 
      List result = new ArrayList(); 
     } 
    }); 
    dialog.setPositiveButton("Cancel", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
      dismissDialog(0); 
     } 
    }); 
    AlertDialog alert = dialog.create(); 
    return alert; 
}

答えて

4

...それsetNagativeButton("Cancel" .....

protected Dialog onCreateDialog(int id) 
{ 
    final AlertDialog.Builder dialog = new AlertDialog.Builder(this); 
    dialog.setMessage("Enter Holla message"); 
    EditText hollaMessage = new EditText(this); 
    dialog.setView(hollaMessage); 
    dialog.setCancelable(false); 
    dialog.setPositiveButton("Send", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int id) { 
      List result = new ArrayList(); 
     } 
    }); 
    dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
      dismissDialog(0); 
     } 
    }); 
    AlertDialog alert = dialog.create(); 
    return alert; 
} 
+0

私は3つのボタンを追加したい場合は、私が何をすべきか? – jfalexvijay

+0

これをstackoverflowのseprateの質問として尋ねてください、そして、それがあなたを助けるなら、答えを受け入れてください。 – Javanator

+0

私はこれをかなりやっていますが、うまくいきません。手伝ってくれますか? http://stackoverflow.com/questions/15439817/alertdialog-builder-not-displaying-buttons –

3

ああ作ります!バディにニュートラルボタンを追加するオプションもあります。
ニュートラルボタンは、ポジティブボタンとネガティブボタンと同様に追加できます。

Now次のコメントは、2つのボタンを2つ追加したい場合です。

次に、すべての4つのボタンのxmlでレイアウトを作成し、それを膨張させます。2ダイアログで設定します。

check this out....これはあなたの疑問をすべて解決します。
ありがとうございます。

+0

ご協力ありがとうございます。 – jfalexvijay

0

任意のボタンの ".show()"末尾を追加します。受験のための :

dialog.setPositiveButton("Cancel", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int which) { 
     dismissDialog(0); 
    } 
}).show(); 
+1

間違った答え、ここであなたはダイアログオブジェクトのshow()メソッドを呼び出していますが、そのsetPositiveButton()メソッドまたはそのボタンには関係しません –

+0

@ShirishHerwadeあなたは正しいです – AwaisMajeed

関連する問題