开发者

How to give validation in forms fields ,in android

I'm a newcomer to android.

I'm creating a registration form in android, and I want to apply validation of some fields, like mobile no., 开发者_运维技巧email, date, etc..

And I want to display a POPUP message, if fields don't match.


and form validation are apply from its xml file..

for temporary popup msg.. Toast.makeText(getApplicationContext(), "your msg", Toast.LENGTH_SHORT).show();


You can create a text view in Xml and set its visibility as GONE then make your validation.. For example check mobile no length

    TextView tv=(textView)findViewById(R.id.textview);
    EditText et=(EditText)findViewById(R.id.edittext);
    mobile_number=et.getText().toString();
    if(mobile_number.length<10){
      tv.setVisibility(View.VISIBLE);
   }else{
     //Some Code
    }

For Dialog boxe check this


u can have a look at this

and for your alert message

@SuppressWarnings("deprecation")
    public void showAlertDialog(Context context, String title, String message,
            Boolean status) {
        AlertDialog alertDialog = new AlertDialog.Builder(context).create();

        // Setting Dialog Title
        alertDialog.setTitle(title);

        // Setting Dialog Message
        alertDialog.setMessage(message);

        if(status != null)
            // Setting alert dialog icon
            //alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);

        // Setting OK Button
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
            }
        });

        // Showing Alert Message
        alertDialog.show();
    }


For showing errors, use the TextEdits setError() method.


I am not sure but its always work for me ,For validation purpose we should use Regular expression which is you can found in Utill.nio package in java.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜