您好我想在動態創建警報對話框時更改警報對話框按鈕文本。這意味着我具有基於該布爾值的布爾值,需要更改警報對話框按鈕文本和佈局警報dalog .Ex: - 如果值爲true,則在警報對話框中應該有一個按鈕,並且按鈕文本爲「YES」,如果爲false,則需要添加兩個按鈕和一個按鈕文本應該變爲「OK」,另一個按鈕爲負按鈕。這應該在創建警報對話框之前進行檢查。到目前爲止,我在創建警報對話框時已更改了文本和版式權重。但它沒有改變任何內容。總是顯示默認xml文件中的警告對話框。在創建警報對話框時動態更改按鈕文本android
View dialogView = getLayoutInflater().inflate(R.layout.dialog_layout, null);
LinearLayout view = (LinearLayout)dialogView.findViewById(R.id.dialog_button_layout);
Button btnYes = (Button) dialogView.findViewById(R.id.btn_yes);
if(value){
view.setWeightSum(1);
btnYes.setText(R.string.yes_text);
}else {
view.setWeightSum(2);
btnYes.setText(R.string.ok_text);
}
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(MyActivity.this,
R.style.OurTheme)).setView(dialogView);
Dialog = builder.create();
Dialog.show();
我真的很感謝你answer.I知道這是什麼,我問我的,但我有使用LayoutInflater()膨脹來獲得父母layout.But您的解決方案沒有按」。 t使用這一個。你可以給我的方式使用LayoutInfalter到你的解決方案。 – Sajithv
而我需要實現AlertDialog而不是對話框。 – Sajithv