0

I want to give ToolTip and Validation message something like these in my Android Application's EditText

Google like validation Message

Validation Images

Is there any property through which i can easily show validation and ToolTip messages?

I would also like to show ToolTip same as Error Message on focus of EditText with icon of error message as green.

Any suggestion on these are most welcome.

Vikalp Patel
  • 10,669
  • 6
  • 61
  • 96

1 Answers1

1

Achieved ToolTip like with help of setError on EditText

e.setError("Enter Username", error_indicator);

Achieved validation message like with help of setError on EditText

e.setError("Enter Username);

Below is the snippet of code:-

EditText e1,e2;
Button submit;
int left = 0;
int top = 0;
private Drawable error_indicator;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    e1=(EditText)findViewById(R.id.editText1);
    e2=(EditText)findViewById(R.id.editText2);
    submit = (Button)findViewById(R.id.button1);
    error_indicator=getResources().getDrawable(android.R.drawable.ic_dialog_info);
    int right = error_indicator.getIntrinsicHeight();
    int bottom = error_indicator.getIntrinsicWidth();

    error_indicator.setBounds(new Rect(left, top, right, bottom));

    submit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
        if(e1.getText().toString()!="")
        {
            e1.setError("Enter Username", error_indicator);
        }
        if(e2.getText().toString()!="")
        {
            e2.setError("Please field");
        }
        }
    });
}
Vikalp Patel
  • 10,669
  • 6
  • 61
  • 96