1

您好我正在尝试编写一个小应用程序,当系统上的这一天是星期天时,它应该会拉出一个对话框,它做得很好。但是,当我将信息放入对话框中的框中并单击提交时,它仍然显示我设置的 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
4

2 回答 2

0

我想,我有你的问题。

sundayDialog.setContentView(R.layout.sunday_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();

}

于 2013-08-06T05:31:53.163 回答
0

我不确定这是否是原因,但每次,您都在重置内容视图。这应该只在 onCreate 中调用一次,否则只需删除元素并使用充气器添加新元素。我认为每次重置内容视图时,都会重置文本框。

于 2013-08-06T05:08:53.337 回答