且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

空验证上的EditText框警告对话框 - 机器人

更新时间:2023-11-19 08:27:34

我想你应该重新创建对话框,因为它似乎在 DialogInterface 的onClick()不给你一个选择停止对话框关闭

I think you should recreate the Dialog, as it seems the DialogInterface given as a parameter in onClick() doesn't give you an option to stop the closure of the Dialog.

我也有一对夫妇的提示您:

I also have a couple of tips for you:

尝试使用 Activity.onCreateDialog() Activity.on prepareDialog(),当然 Activity.showDialog()。他们使对话框的使用更容易(ATLEAST对我来说),也对话框使用看起来更像是菜单的使用。使用这些方法,你也能更easilty再次显示该对话框。

Try using Activity.onCreateDialog(), Activity.onPrepareDialog() and of course Activity.showDialog(). They make dialog usage much easier (atleast for me), also dialog usage looks more like menu usage. Using these methods, you will also be able to more easilty show the dialog again.

我想给你一个提示。这不是一个回答你的问题,但在回答这样做是更具可读性。

I want to give you a tip. It's not an answer to your question, but doing this in an answer is much more readable.

,你可以简单地做:

new AlertDialog.Builder(this)
.setTitle("Record New Track")
.setMessage("Please Name Your Track:")
//and some more method calls
.create();
//or .show();

节省您参考,并大量的输入)。 (几乎?) AlertDialog.Builder 的所有方法返回一个 AlertDialog.Builder 的对象,你可以直接调用的方法上。

Saves you a reference and a lot of typing ;). (almost?) All methods of AlertDialog.Builder return an AlertDialog.Builder object, which you can directly call a method on.

这同样适用于吐司 S:

Toast.makeText(this, "Please enter...", Toast.LENGTH_LONG).show();