0

I have following small block of code to set validation on edit text when a button is pressed and display the validation message in a dialog.

Java Code

setContentView(R.layout.addnewcontacts);
            Button buttonSave = (Button) findViewById(R.id.buttonSave);
            final EditText editTextName = (EditText) findViewById(R.id.editTextName);
            buttonSave.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    if (editTextName.getText().toString().length() == 0) {
                        editTextName.setError( "First name is required!" );

                    }
                }
            });
        }

Code is working fine but the popup is not displaying text in it.

Screen shot :

enter image description here

Why popup is not showing text?

sonia
  • 405
  • 2
  • 7
  • 23

5 Answers5

1

Call EditText.setError() with a SpannableStringBuilder object.

Check this previous SO question: Android EditText.setError() yields invisible error text

Community
  • 1
  • 1
Divya Motiwala
  • 1,659
  • 1
  • 16
  • 24
0

Use EditText.setTextColor(int color) to set the required color for the text element.

Premsuraj
  • 2,506
  • 1
  • 17
  • 16
0

Just add edittext color into your xml file.

    <EditText
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:textColor="@android:color/black" />
0

it's very simple just follow the below code it is working fine.

final EditText et=(EditText)findViewById(R.id.editText1);
    Button bt=(Button)findViewById(R.id.button1);
    bt.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            if(et.getText().toString().length()==0){
                et.setError("it is wrong");
            }
        }
    });
Baadsah
  • 53
  • 6
0

please check the theme you have applied .Use basic theme to check error text