如何设置警报框

发布于 2024-10-22 11:50:41 字数 162 浏览 1 评论 0原文

在我的应用程序中,我放置了三个带有“确定”按钮的编辑框。在按下“确定”按钮之前,用户必须输入所有编辑文本字段,如果任何编辑文本留空,我想给出一个警报框。

在编辑文本框中,诸如“姓名”、“年龄”之类的字段名称应该是缩小的,并且当单击它时它必须消失。

如何做到这一点,请任何人帮助我

in my app i have placed three edit boxes with a ok button. Before pressing the ok button the user must enter all the edit text fields, if any of the edit text is been left empty i want to give an alert box.

in the edit text box the field name such as "Name", "Age" should be in diminished and when it is clicked it must get disappeared.

How to do this , pls anyone help me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

俏︾媚 2024-10-29 11:50:41

检查长度:

if (edit1.getText().length() > 0 && edit2.getText.length() > 0 && edit3.getText.length() > 0) {
    // Do your normal code here 
} else {
    // Call your alert dialog creation
}

减少?您的意思是提示(当字段中没有文本时显示)?这样做是这样的...

EditText 字段内的 XML:

android:hint="Clear by clicking"

源代码:

nameEditText.setHint("Clear by clicking");

单击时删除文本(如果您已经创建了一个名为 nameEditText 的 EditText 字段):

    // Clear text when clicked
    nameEditText.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            nameEditText.setText("");
        }
    });

然后执行 Vladimir 所说的操作

Check length:

if (edit1.getText().length() > 0 && edit2.getText.length() > 0 && edit3.getText.length() > 0) {
    // Do your normal code here 
} else {
    // Call your alert dialog creation
}

Diminished? You mean a hint (which is shown when there's no text in the field)? This is done like this...

XML inside the EditText field:

android:hint="Clear by clicking"

Source code:

nameEditText.setHint("Clear by clicking");

Remove text on click (if you have already created an EditText field called nameEditText):

    // Clear text when clicked
    nameEditText.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            nameEditText.setText("");
        }
    });

And then do what Vladimir said

吐个泡泡 2024-10-29 11:50:41

只需使用 AlertDialog 即可。检查所有条件,如果有错误,则构建一个对话框并显示它。

Just use AlertDialog. Check all the conditions and if there is an error build a dialog and show it.

辞别 2024-10-29 11:50:41

你可以在你的activity中设计这个ui,并且这个activity应该有主题android:theme="@android:style/Theme.Dialog"。当你希望你的活动消失时。只需调用finish()

you can design this ui in your activity, and this activity should have the theme android:theme="@android:style/Theme.Dialog". And when you want your activity to disappear. simpally call finish()

不必了 2024-10-29 11:50:41

很简单..
用于名称检查:

if(editname.getText().tostring().length==0)

显示警报...

AlertDialog.Builder builder=new AlertDialog.Builder(context);
builder.setTitle("something,");
builder.setMessage("something..");
builder.show():

您还可以添加按钮...通过

builder.setNeutralButton("name",new DialogInterface.onclick
............}

its simple..
for name checking :

if(editname.getText().tostring().length==0)

show alert...

AlertDialog.Builder builder=new AlertDialog.Builder(context);
builder.setTitle("something,");
builder.setMessage("something..");
builder.show():

you can also add button...by

builder.setNeutralButton("name",new DialogInterface.onclick
............}
白云悠悠 2024-10-29 11:50:41

试试这个

   AlertDialog.Builder alert = new AlertDialog.Builder(this);
                alert.setMessage("Error Msg).setPositiveButton("OK", alertClickListener).show();

        DialogInterface.OnClickListener alertClickListener = new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialog, int which) 
        {

        }
    };

just try this

   AlertDialog.Builder alert = new AlertDialog.Builder(this);
                alert.setMessage("Error Msg).setPositiveButton("OK", alertClickListener).show();

        DialogInterface.OnClickListener alertClickListener = new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialog, int which) 
        {

        }
    };
饮湿 2024-10-29 11:50:41

在您的 Ok Button OnClick 中执行以下操作

    if (et1.getText().toString().length() != 0) {
     emailid = String.valueOf(et1.getText());
    }
    if((emailid==null|| emailid=="")){
        tvError.setVisibility(View.VISIBLE);
        tvError.setText("All fields are Mandatory");
        Toast.makeText(Signin.this,"All fields are Mandatory", Toast.LENGTH_SHORT).show();
    }else{
              // Your operation
         }

,其中 et1 是编辑框 1,emailid 是字符串。

在您的 XML 文件中创建一个带有选项 android:visibility="GONE" 的文本视图。

现在在 if 部分中,如果发生错误,则使该文本视图可见或在其他地方做你的过程..

你也可以保留吐司消息...

In your Ok Button OnClick do the following

    if (et1.getText().toString().length() != 0) {
     emailid = String.valueOf(et1.getText());
    }
    if((emailid==null|| emailid=="")){
        tvError.setVisibility(View.VISIBLE);
        tvError.setText("All fields are Mandatory");
        Toast.makeText(Signin.this,"All fields are Mandatory", Toast.LENGTH_SHORT).show();
    }else{
              // Your operation
         }

where et1 is Edit box 1,emailid is String ..

In your XML file create a textview with option android:visibility="GONE"..

Now in if part Make that textview visible if error occurs or do your process in Else..

Also you can keep toast mesaage...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文