相关疑难解决方法(0)

alertDialog.getButton()方法给出了空指针异常android

我打算用layout_weight = 1创建3个按钮,对自定义对话框不感兴趣.所以我写了下面的代码.它不工作.总是是按钮给我null.这段代码怎么了?

  AlertDialog dialog= new AlertDialog.Builder(this).create();
            dialog.setIcon(R.drawable.alert_icon);
            dialog.setTitle("title");
            dialog.setMessage("Message");
            dialog.setButton(AlertDialog.BUTTON_POSITIVE,"Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface arg0, int arg1) {
                                                }
            });
            Button yesButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
            Log.w("Button",""+yesButton);//here getting null
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1f);
            yesButton.setLayoutParams(layoutParams);
            dialog.show();
Run Code Online (Sandbox Code Playgroud)

此致,Android开发人员.

android android-alertdialog

44
推荐指数
3
解决办法
3万
查看次数

标签 统计

android ×1

android-alertdialog ×1