Make EditText field to be Required

I have a screen with three tabs. User can enter stuff in all three tabs in any order. However  one of text fields is required and can’t be left blank before leaving this whole activity. This is a field I have to show once they exit this activity.

How do I do that?  Let’s gather info.

1. Not directly applicable yet,  how to gve error

if( userName.getText().toString().trim().equals(""))
   userName.setError( "First name is required!" );

    userName.setHint("please enter username")
 } else { .. go on to other activity }
2. Decorate editText with an image

// decorate with edit pencil
EditText item = (EditText) mDrillAct.findViewById(;
Drawable x = mAct.getResources().getDrawable(R.drawable.edit);
x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight());
item.setCompoundDrawables(null, null, x, null);
// done decorating

this creates a pencil image at the right edge of EditText. Pretty.

Together with code above we have required field and a prompt for entering text.

This was easy!


2 thoughts on “Make EditText field to be Required

  1. I was very pleased to discover this website. I wanted to thank you for your time for this fantastic read!! fbdkcdaekadg

  2. Usually I do not read writeup on blogs, nevertheless I wish to say that this writeup extremely forced me to take a look at and do so! Your writing taste has been amazed me. Thanks, really wonderful post. efgkafdkbebc

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s