如何检查编辑文本为空 [英] How to check edit text is empty

查看:171
本文介绍了如何检查编辑文本为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发中,如果我点击一个按钮,它ð竟被检查所有编辑文本是空的或书面的东西,并提供类似的警告框为message.I做了一个方法,并调用它的onclick事件的应用程序。但我没能得到期望的结果为语法错误不是医生甚至不logcat中显示任何错误,请帮我...在此先感谢..

 的ImageButton B2 =(的ImageButton)findViewById(R.id.imageButton2);   b2.setOnClickListener(新OnClickListener()
   {    @覆盖
    公共无效的onClick(查看为arg0){
        校验值();    }    私人无效校验值(){
        的EditText E =(EditText上)findViewById(R.id.editText1);
           E1的EditText =(EditText上)findViewById(R.id.editText2);
           的EditText E2 =(EditText上)findViewById(R.id.editText3);
           E3的EditText =(EditText上)findViewById(R.id.editText4);
           E4的EditText =(EditText上)findViewById(R.id.editText5);
           E5的EditText =(EditText上)findViewById(R.id.editText6);
        串f = e.getText()的toString()。
         字符串F1 = e1.getText()的toString()。
           字符串F2 = e2.getText()的toString()。
           字符串F3 = e3.getText()的toString()。
           字符串F4 = e4.getText()的toString()。
           字符串F5 = e5.getText()的toString()。        如果((f.length()>0)&&(f1.length()>0)&&(f2.length()>0)&&(f3.length()>0)&&(f4.length()>0)&&(f5.length()>0)) {            AlertDialog警报=新AlertDialog.Builder(Test.this).create();
            alert.setTitle(异常:未完成表);
            alert.setMessage(看起来你错过了一个领域或取得了mistake.Please保证形式的所有领域都filled.Click OK转到主页);            alert.setButton(OK,新DialogInterface.OnClickListener(){                  公共无效的onClick(DialogInterface对话,诠释它){
                      意图I =新意图(Test.this,ShpoonkleActivity.class);                }});           }
        其他
        {
            AlertDialog警报=新AlertDialog.Builder(Test.this).create();
            alert.setTitle(你的表格是成功processed.Thanks);
            alert.setMessage(完成后请留意确认电子邮件如果你没有在未来24小时送一,再次打开这个表,并确保youremail是正确的!);        }
    }
    });}
    }


解决方案

你可以试试这个:

  IF((f.trim()。等于('')||(f1.trim()。等于('')|| ........ ){    //错误,一个或多个EDITTEXT是空的}
其他
{
    //所有EDITTEXT不为空
}

I am developing a application in which if i click a button it woul d check that all the edit text are empty or something written and providing similar alert box for that message.I had made a method and calling it in Onclick event.But i am not able to get the desired result as syntax error is not dr even logcat not showing any error please help me out...Thanks in advance..

    ImageButton b2=(ImageButton)findViewById(R.id.imageButton2);

   b2.setOnClickListener(new OnClickListener()
   {

    @Override
    public void onClick(View arg0) {
        checkValue();

    }

    private void checkValue() {
        EditText e = (EditText) findViewById(R.id.editText1);
           EditText e1 = (EditText) findViewById(R.id.editText2);
           EditText e2 = (EditText) findViewById(R.id.editText3);
           EditText e3 = (EditText) findViewById(R.id.editText4);
           EditText e4 = (EditText) findViewById(R.id.editText5);
           EditText e5 = (EditText) findViewById(R.id.editText6);
        String f = e.getText().toString();
         String f1 = e1.getText().toString(); 
           String f2 = e2.getText().toString();
           String f3 = e3.getText().toString();
           String f4 = e4.getText().toString();
           String f5 = e5.getText().toString();

        if ((f.length()>0)&&(f1.length()>0)&&(f2.length()>0)&&(f3.length()>0)&&(f4.length()>0)&&(f5.length()>0)) { 

            AlertDialog alert= new AlertDialog.Builder(Test.this).create();
            alert.setTitle("Exception:Incomplete Form");
            alert.setMessage("Looks like you missed a field or made a mistake.Please ensure all fields of form are filled.Click OK to go to main page");

            alert.setButton("OK", new DialogInterface.OnClickListener() {

                  public void onClick(DialogInterface dialog, int which) {
                      Intent i=new Intent(Test.this,ShpoonkleActivity.class);

                } }); 

           } 
        else
        {
            AlertDialog alert= new AlertDialog.Builder(Test.this).create();
            alert.setTitle("Your Form is successfully processed.Thanks");
            alert.setMessage("You are Done! Keep an eye out for a confirmation email. If you don't get one in the next 24h, open this form again, and make sure youremail is correct");

        }


    }
    });

}
    }

解决方案

you can try this :

if ((f.trim().equals('') || (f1.trim().equals('') ||........) { 

    // Error , one or more editText are empty

}
else
{
    // all editText are not empty 
}

这篇关于如何检查编辑文本为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆