Pages

Saturday 18 February 2012

Set Validation error for edittext in android

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:

1 comment:

  1. hi, I want to display image while entering word in edittext else it should not display, can u help me the code .. its urgent

    ReplyDelete