0
我試圖在用戶從列表對話框中選擇數量後更新對話框的內容。比如現在用戶呈現我的「添加項目對話框」: 如何更新對話框的內容
,默認數量爲1,但如果用戶決定他/她想要的添加量更壓力機(中性)按鈕,它是出現另一個對話框: 問題是,在用戶選擇一個數量後,我的代碼沒有刷新第一個對話框的內容,因爲我想要的,它仍然表示爲1. 順便說一句我正在使用第三方library進行創建對話框 這是我的代碼:
final int[] choosenQuantity = {1};
final String[] str = {""};
final MaterialDialog.Builder addItemBuilder = new MaterialDialog.Builder(this)
.title("Add Item")
.widgetColor(getResources().getColor(R.color.ColorPrimaryDark))
.inputMaxLength(30, R.color.material_blue_grey_950)
.content("Quantity: "+choosenQuantity[0]+"")
.inputType(InputType.TYPE_CLASS_TEXT)
.autoDismiss(false)
.input("add shopping item", "", new MaterialDialog.InputCallback() {
@Override
public void onInput(MaterialDialog dialog, CharSequence input) {
str[0] = input.toString();
//add it to shoppingListItems and save to sharedPreferences
if (str[0].length() != 0) {
shoppingListItems.add(str[0] + " (" + choosenQuantity[0] + ")");
saveShoppingItems();
isListEmpty();
dialog.dismiss();
} else {
Toast.makeText(MainActivity.this, "no item description!", Toast.LENGTH_LONG).show();
}
}
}).negativeText("Cancel").callback(new MaterialDialog.ButtonCallback() {
@Override
public void onNegative(MaterialDialog dialog) {
super.onNegative(dialog);
dialog.dismiss();
}
});
addItemBuilder.neutralText("Add Quantity").callback(new MaterialDialog.ButtonCallback() {
@Override
public void onNeutral(final MaterialDialog dialog) {
super.onNeutral(dialog);
MaterialDialog.Builder quantityDialogBuilder = new MaterialDialog.Builder(MainActivity.this);
quantityDialogBuilder.title("Add Quantity");
quantityDialogBuilder.items(R.array.Quantaty_array);
quantityDialogBuilder.itemsCallback(new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
choosenQuantity[0] = which+1;
addItemBuilder.content("Quantity: "+choosenQuantity[0]+"");
}
}).show();
}
}).show();
謝謝你的回答,但這並不解決問題:/ –
嘗試獲得該對話框的視圖參考,並更新文本。參考編輯的答案。 –