45

このボタンをクリックすると、次のように単一の AlertDialog で複数のボタンを開きたい:ここに画像の説明を入力

助けてください :

私はこれを使用していました....複数のボタンを追加する

alertDialog.setButton(delete, "Delete", new OnClickListener() {
        
        public void onClick(View v) {
            // TODO Auto-generated method stub
            
        }
    });

しかし、私は見つけました...、 setButton() を setButton2().. のようなものに変更します..... wt xcan i do this....

4

5 に答える 5

21

独自のカスタム ビュー (my_alert_dialog.xml) を使用して AlertDialog を拡張します。

AlertDialog.Builder alert = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
//inflate view for alertdialog since we are using multiple views inside a viewgroup (root = Layout top-level) (linear, relative, framelayout etc..)
View view = inflater.inflate(R.layout.my_alert_dialog, (ViewGroup) findViewById(R.id.root)); 

Button button1 = (Button) view.findViewById(R.id.button1); // etc.. for button2,3,4.
alert.setView(view);
alert.show();
于 2012-09-03T08:25:38.023 に答える
3

自分でビューを作成しない場合は、3 つのボタンを持つ Alertdialog しか作成できません。

xml で独自のカスタム ビューを作成することもできます。

しかし、リストを作成することをお勧めします。

http://developer.android.com/guide/topics/ui/dialogs.html#AlertDialog 「リストの追加」を確認 してください

于 2012-09-03T08:27:51.047 に答える
0
Dialog dialog = new Dialog(context);
RelativeLayout featureLayout = (RelativeLayout) View.inflate(this, R.layout.yourview, null);
dialog.setContentView(featureLayout);
dialog.show();
于 2012-09-03T08:29:52.550 に答える