Tuesday, December 27, 2011

Set Validation error for edittext in android

Set Validation error for edittext in android

Prob:

suppose user not fill the edittext filed  at the time we can show alert\error msg .

Solution:

we can solve this issue using setError().

ex code:
  @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btn =(Button)findViewById(R.id.button1);
        btn.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {
                 EditText edittext =(EditText)findViewById(R.id.editText1);
                if(edittext.getText().length()==0){
                    edittext.setError("please enter the value");
                }

            }
        });
    }

screen shot:


2 comments:

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...