您好我正在尝试编写一个小应用程序,当系统上的星期日是星期日时,它应该会拉出一个对话框,它正在做得很好。但是,当我将信息放在对话框的框中并单击“提交”时,它仍然显示我已设置的emptyBox的第二个对话框。
所以回顾一下对话框的所有项目都在工作,除了系统仍然看到EditText框为空,但那里有一个值。价值只会是数字。
final Dialog sundayDialog = new Dialog(this);
sundayDialog.setContentView(R.layout.sunday_dialog);
Button sundaySubmitBtn = (Button) sundayDialog
.findViewById(R.id.sundayDialogSubmitBtn);
Button sundayCancelBtn = (Button) sundayDialog
.findViewById(R.id.sundayDialogCancelBtn);
sundaySubmitBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Submit Button
setContentView(R.layout.sunday_dialog);
final EditText etAmountBought = (EditText) findViewById(R.id.amountBoughtET);
final EditText etCost = (EditText) findViewById(R.id.pricePaidET);
String amountBought = etAmountBought.getText().toString();
String cost = etCost.getText().toString();
if (amountBought.isEmpty() || cost.isEmpty()) {
//sundayDialog.dismiss();
emptyETDialogCall();
} else {
try {
mAmountBought = Integer.parseInt(amountBought);
mPricePaid = Integer.parseInt(cost);
} catch (NullPointerException e) {
Log.e(TAG, "Error in sunday dialog in try/catch");
}
}
if (mPricePaid >= 250) {
costTooHighDialogCall();
mPricePaid = 0;
}
// textBlockDisplay(); // Update the text block with input.
}
});
sundayCancelBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Cancel Button
sundayDialog.dismiss();
sundayCancelDialog();
}
});
sundayDialog.show();
}
这是logcat中唯一显示的内容:
08-04 11:42:44.780: W/IInputConnectionWrapper(1209): finishComposingText on inactive InputConnection
答案 0 :(得分:0)
我不确定这是否是原因,但每次都要重置内容视图。这应仅在onCreate中调用一次,否则只需删除元素并使用inflater添加新元素。我想每次重置内容视图时,它都会重置文本框。
答案 1 :(得分:0)
我想,我遇到了你的问题。
<强> sundayDialog.setContentView(R.layout.sunday_dialog); 这是您为自定义对话框设置的视图。这很好。
再次点击按钮后,您将重置布局 这会再次创建所有视图,并且您将重置所有内容。
final Dialog sundayDialog = new Dialog(this);
sundayDialog.setContentView(R.layout.sunday_dialog);
Button sundaySubmitBtn = (Button) sundayDialog
.findViewById(R.id.sundayDialogSubmitBtn);
Button sundayCancelBtn = (Button) sundayDialog
.findViewById(R.id.sundayDialogCancelBtn);
sundaySubmitBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Submit Button
//这里我删除了setContent View ....
final EditText etAmountBought = (EditText) findViewById(R.id.amountBoughtET);
final EditText etCost = (EditText) findViewById(R.id.pricePaidET);
String amountBought = etAmountBought.getText().toString();
String cost = etCost.getText().toString();
if (amountBought.isEmpty() || cost.isEmpty()) {
//sundayDialog.dismiss();
emptyETDialogCall();
} else {
try {
mAmountBought = Integer.parseInt(amountBought);
mPricePaid = Integer.parseInt(cost);
} catch (NullPointerException e) {
Log.e(TAG, "Error in sunday dialog in try/catch");
}
}
if (mPricePaid >= 250) {
costTooHighDialogCall();
mPricePaid = 0;
}
// textBlockDisplay(); // Update the text block with input.
}
});
sundayCancelBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Cancel Button
sundayDialog.dismiss();
sundayCancelDialog();
}
});
sundayDialog.show();
}