package com.coderzheaven.seterror; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_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("Field cannot be left blank."); } } }); } }
Free Android Tutorials, Android Tips, Android Developments, Free Android Codings., Free Android App Examples, Open Source Code for Android
Saturday, 13 October 2012
How to show error in an EditText using setError() in Android?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment