4

Background

On Android, you can set an error indication for any EditText view when you want to show the user that what is typed there (or not typed) is wrong (called "form validations").

There is even a nice library for this (here) , and many post here are available of how to use it.

All worked well for me till I've ran it on a nexus 4 with Android 4.2 .

The problem

Sometimes, it just won't show the icons of the errors. In such a case , only when i give the editText (that has the problem) focus, it shows the bubble, but it's empty and doesn't show the icon of the error.

Also, in all cases, the bubbles are always empty.

Why does it occur, and how can I fix it?

Note: I use actionBarSherlock library so I need to use their themes or a theme that is based on theirs.


EDIT:

here are some screenshots:

android 4.2.2 :

enter image description here

android 2.3.5 :

enter image description here


EDIT:

after i thought that this was solved by itself, i've finally figured out when this bug occurs: if the focus is on another editText which doesn't have an error, and the error of validation is on another editText , the indicator isn't shown till the editText gets focus.

android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • It's not empty I think but its just showing white colored background without any text, right ? – Paresh Mayani Jun 05 '13 at 07:07
  • maybe, but the worst thing is that it doesn't show the icons indicators, so the user can't see that something is wrong, and where is the problem . nothing. only when you click on the problematic field you can see it, and even then it's empty (or has white text on white background) . – android developer Jun 05 '13 at 08:06
  • I've done a similar activity in the past and I didn't get any problem. Can you show the relevant code? Maybe there's something missing. – Akatosh Jun 12 '13 at 09:23
  • Which theme are you using? Theme.Light or any? Include it in your question. – Paresh Mayani Jun 12 '13 at 10:17
  • as i can see in the sample, it's the light theme. i also used it on my app, but i could also use other themes that are based on it. – android developer Jun 12 '13 at 11:43

1 Answers1

4

Problem 1: The problem is the Theme of the application. Try changing the theme to some darker theme like:

<style name="AppBaseTheme" parent="android:Theme.Black">

and it should solve your problem. I found this similar issue earlier and rectified this by changing the theme. But I didn't research much but I feel that this is Android issue and the bubble should try to change the text colour according to the theme.

Let me know if it solves your problem, or not.

Problem 2: The other issue you are talking about for not taking focus, you may consider the following link: Text Truncating and Focus Issue.

----------------------------------------Updated Answer---------------------------------------------

Q1) What should I add to the theme configuration in order for it to always work, no matter what theme I use? 

According to my findings here are some results:

[Note: Only applicable for devices running 3.0 and up]

If your build target is:

  • less than 11, then using

    parent="android:Theme.Light"    --> setError() message doesn't work or shows very faded text colour almost blending with color white
    parent="android:Theme"      --> setError() message works
    
  • greater than 11, then using

    parent="android:Theme.Holo.Light" --> setError() message works
    parent="android:Theme.Holo"       --> setError() message works
    

Since, your project is supported for devices less than 11 API level and you want to support 4.0 and plus too, your best bet would be to go and integrate HoloEverywhere in your project which will solve your problem and you will be able to use your ActionBarSherlock too, for compatibility, check this SO Post.

Q2) What are the available configurations for the error indication UI ?

Mostly you can customise drawables and icons but I doubt you will be able to configure your text and background(If anyone knows more may point out on this)

I would suggest you to check this SO Post for immediate answers.

And for placing the correct focus, for every validation checks, you may place this code:

EditText.setFocusableInTouchMode(true);
EditText.requestFocus();
EditText.setError("My Error Text");

Let me know for any issues.

Community
  • 1
  • 1
abhy
  • 933
  • 9
  • 13
  • +1 the same issues I faced and I resolved by removing the Holo Theme. – Padma Kumar Jun 12 '13 at 09:54
  • but i need to use this theme. more importantly (and sorry for not mentioning it) i use actionBarSherlock, so it needs to have its own themes. – android developer Jun 12 '13 at 09:57
  • why the `NoTitleBar.Fullscreen`? – njzk2 Jun 12 '13 at 10:01
  • @androiddeveloper I never worked with ActionBarSherlock, but you may try with different themes available if it comes close to your requirement. – abhy Jun 12 '13 at 10:13
  • @njzk2 Came as an extra with auto suggest, thanks for pointing. Edited and fixed. – abhy Jun 12 '13 at 10:14
  • What should I add to the theme configuration in order for it to always work, no matter what theme I use? What are the available configurations for the error indication UI ? – android developer Jun 12 '13 at 11:31
  • @abhy so if i want to support both API 11 and above versions and API 10 and below , i need to use this library ? surely the library has some configurations that made it work for you, no? couldn't we find out the difference between the theme of actionBarSherlock and this library, and see what needs to be changed? – android developer Jun 13 '13 at 07:52
  • @androiddeveloper May be they both can be fused but I doubt, if they can be then it would require lot of time(dedicated 1 or 2 days), I guess :) – abhy Jun 13 '13 at 09:43
  • sadly i can't reproduce the problem anymore, and it's probably because i used an old version of actionBarSherlock. sorry for all the time you've wasted on this. – android developer Jun 16 '13 at 12:48
  • Not an issue, it may help someone else :) Atleast I know now exactly that Error Indicators are not working on which conditions and moreover I will be careful not to use older version of actionBarSherlock. – abhy Jun 16 '13 at 16:18
  • no i was wrong. i've edited my question again to show how to reproduce the problem. now i can say that the solution is to request focus when you do the validation. what a weird bug. you've earned your reward. i would be glad if you could help with other questions that i've asked, like this one: http://stackoverflow.com/questions/16591536/actionbarsherlock-doesnt-support-light-theme-alert-dialogs – android developer Jun 17 '13 at 09:52
  • i'm not sure though why and when i got an error that has white text on white background. – android developer Jun 17 '13 at 10:21
  • sure buddy I will look into them and will try to reply aptly if I know about it. – abhy Jun 18 '13 at 13:14