Iam bào tạo cho tạo 3 nút với layout_weight = 1, không quan tâm đến hộp thoại tùy chỉnh. Vì vậy, tôi đã viết dưới đây code.It không hoạt động. Luôn luôn có nút mang lại cho tôi null . Có gì sai trong mã này?alertDialog.getButton() phương pháp cung cấp cho con trỏ ngoại lệ android android
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();
Kính trọng, Nhà phát triển Android.
Tuy nhiên vấn đề persist.No Sử dụng liên kết đó. – ADIT
Vui lòng đọc chú thích # 4, sử dụng dialog.show(); trước khi sử dụng getButton() – vieux
Cảm ơn wieux.It đang hoạt động – ADIT