10

I am on Android 4+ and I am trying to add hints to my edit text widgets. I tried adding the hint to the layout as follows...

 <EditText
        android:id="@+id/bar_name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="text"
        android:hint="@string/bar_name_hint"
        />

But when I focus on the Text box it writes over the hint instead of the hint disappearing.

enter image description here

I found documentation on adding a onFocus listener to the EditText, but I would like to avoid doing this programatically. The post below also mentioned using selectors but I can't find documentation on how to do that.

Android EditText Hint

So what is the best way to handle this?

I wrote this as recomended here by @A--C and @Flexo because they say "comments that say nothing beyond "me too" are just noise." and it's better to ask the same question again.

Comments like that are very useful as a way to contact the 1st person with the problem... maybe he has already fixed it and can post an answer that will be useful for everybody but didn't posted yet because he thought nobody would care.

I'm not going to post answers to questions only to get points so I can comment... I have more stuff to do... It should be available to everybody anyway.

I wouldn't be posting this if I hadn't tried EVERYTHING to fix my problem.

Community
  • 1
  • 1
xpete
  • 417
  • 3
  • 14
  • 2
    what device are you testing on? – FoamyGuy Dec 30 '12 at 02:47
  • do you can post all xml code? – ademar111190 Dec 30 '12 at 02:50
  • Unfortunately I think `` is only valid to be applied in making state lists out of Drawable and Color resources, it does not yet work for Strings. Best thing would be to do it via code(and its easy too so why not) – Vrashabh Irde Dec 30 '12 at 03:24
  • First of all, is the user actually TYPING the text input or are you putting it in the field some other way? Do all your applications suffer from the same problem? Including new test applications? Does it happen on all devices, including the emulator (stock and BlueStacks)? – Paul-Jan Dec 30 '12 at 06:28
  • possible duplicate of [android:hint not disappearing onFocus using EditText](http://stackoverflow.com/questions/9656492/androidhint-not-disappearing-onfocus-using-edittext) – SztupY Dec 30 '12 at 12:08
  • @FoamyGuy, Nexus S Slartibartfast, how is that related to may problem? Paul-Jan, the text is written from the code. No. No. Yes(didn't tried BlueStack). SztupY, really?! Don't tell!! Thanks FoamyGuy, ademar11190, Slartibartfast, Paul-Jan and SztupY for trying to help but I just fixed the problem before reading your questions... I'am going to post the awswer. – xpete Dec 31 '12 at 19:16

1 Answers1

11

For some reason, I had the activity and fragment layout set twice. On Activity onCreate:

    protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.edit_consumption);

and on the fragment onCreateView:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.edit_consumption, null);

So I had 2 layers of layout. I only had to remove that layout from the Activity onCreate to fix the problem.

xpete
  • 417
  • 3
  • 14