0

Below is an Android screen that I am developing.

An AnDroid screen

If user input data is not correct when the next button is pressed, I would like to move the views below the button downward so that I can display error messages. (For example, "name cannot be blank")

How can I do that?

Sandah Aung
  • 6,156
  • 15
  • 56
  • 98

2 Answers2

0

Try this inside button click event

editTextName.setError("name cannot be blank");
Chirag Ghori
  • 4,231
  • 2
  • 20
  • 35
0

The simplest approach is to use yourEditText.setError("error.."), but be aware there is a bug in this for 4.2

If you want to be specific with the design, you can add a TextView below your EditText and make sure that your TextView visibility is set to View.GONE. When you run your validation method, you just need to set the view to View.VISIBLE if there is an error, respectively. Android will handle reflowing the layout.

Community
  • 1
  • 1
Ben Pearson
  • 7,532
  • 4
  • 30
  • 50