Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在单个AlertDialog上添加多个按钮_Android - Fatal编程技术网

Android 如何在单个AlertDialog上添加多个按钮

Android 如何在单个AlertDialog上添加多个按钮,android,Android,我有一个按钮,单击此按钮后,我想在一个AlertDialog上打开多个按钮,如下所示: 给我一个帮助: 我在用这个。。。。添加多个按钮的步骤 alertDialog.setButton(delete, "Delete", new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub

我有一个按钮,单击此按钮后,我想在一个AlertDialog上打开多个按钮,如下所示:

给我一个帮助:

我在用这个。。。。添加多个按钮的步骤

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

但我发现…,将setButton()更改为setButton2()。。类似于。。。。。wt xcan i do for this…

我将使用自己的自定义视图(my_alert_dialog.xml)膨胀AlertDialog


如果您不自己创建视图,则只能创建带有3个按钮的Alertdialog

您可以使用xml创建自己的自定义视图

但我建议你列个清单

检查
“添加列表”

没有xml的简单解决方案

AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Title");
builder.setItems(new CharSequence[]
        {"button 1", "button 2", "button 3", "button 4"},
        new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // The 'which' argument contains the index position
                // of the selected item
                switch (which) {
                    case 0:
                        Toast.makeText(context, "clicked 1", Toast.LENGTH_SHORT).show();
                        break;
                    case 1:
                        Toast.makeText(context, "clicked 2", Toast.LENGTH_SHORT).show();
                        break;
                    case 2:
                        Toast.makeText(context, "clicked 3", Toast.LENGTH_SHORT).show();
                        break;
                    case 3:
                        Toast.makeText(context, "clicked 4", Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        });
builder.create().show();
int项=0;
ArrayList=新建ArrayList();
ArrayList intList=新的ArrayList();
列表。添加(“A”);
列表。添加(“B”);
列表。添加(“C”);
列表。添加(“D”);
项目=-1;
对于(inti=0;i{
CXLog.d(标记“选择额定值::”+额定值);
CXLog.d(标记“评论反馈”+评论);
项目--;
显示BaralertDialog(请求ID);
});
显示(CXBaseActivity.this.getFragmentManager(),“alertDialog”);
}
}

makes自定义对话框并将布局xml文件扩展到
setVIew()
it。现在添加任意数量的按钮。非常好的示例,比其他按钮更容易理解!非常感谢。这对我有用!但是,这会为您提供一个垂直列表,而不是水平列表。比其他解决方案更好。但是如何为对话框内容添加消息?@teapeng:builder.setMessage()会覆盖这些按钮,因此我想您只剩下builder.setTitle()
Dialog dialog = new Dialog(context);
RelativeLayout featureLayout = (RelativeLayout) View.inflate(this, R.layout.yourview, null);
dialog.setContentView(featureLayout);
dialog.show();
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Title");
builder.setItems(new CharSequence[]
        {"button 1", "button 2", "button 3", "button 4"},
        new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // The 'which' argument contains the index position
                // of the selected item
                switch (which) {
                    case 0:
                        Toast.makeText(context, "clicked 1", Toast.LENGTH_SHORT).show();
                        break;
                    case 1:
                        Toast.makeText(context, "clicked 2", Toast.LENGTH_SHORT).show();
                        break;
                    case 2:
                        Toast.makeText(context, "clicked 3", Toast.LENGTH_SHORT).show();
                        break;
                    case 3:
                        Toast.makeText(context, "clicked 4", Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        });
builder.create().show();
int item = 0;
ArrayList<String> list = new ArrayList<String>();
ArrayList<Integer> intList = new ArrayList<Integer>();
list.add("A");
list.add("B");
list.add("C");
list.add("D"); 
item = -1; 

 for (int i = 0; i < list.size(); i++) { 
    item++; 
    intList.add(i); 
  }

showRatingBarAlertDialog(intList);

private void showRatingBarAlertDialog(ArrayList<Integer> Id) {
    if (item != -1) {
        RatingFragment alertDialog = RatingFragment.instance(BaseActivity.this, Id.get(item), (ratingValue, comments) -> {
            CXLog.d(TAG, "select the rating::" + ratingValue);
            CXLog.d(TAG, "comment the feednback  " + comments);
            item--;
            showRatingBarAlertDialog(requestId);
        });
        alertDialog.show(CXBaseActivity.this.getFragmentManager(), "alertDialog");
    }
}