0

My app has been written for SDK 1.5 3.0 but when it is running on later versions the hints are not appearing in the EditText views. Any suggestions please? Cheers, Rick

Here is the xml layout code:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/scrollView1"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#123456"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="10dp" >

    <TextView
        android:id="@+id/warningTV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:gravity="center_horizontal"
        android:text="@string/warningTV"
        android:textColor="#FFFFFF"
        android:textSize="20sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/csTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/csTitle"
        android:textColor="#FFFFFF"
        android:textSize="20sp" />

    <EditText
        android:id="@+id/csET"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:textColor="#123456"
        android:gravity="center_horizontal"
        android:hint="@string/csET" 
        android:inputType="numberDecimal" />

    <TextView
        android:id="@+id/diaTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/diaTitle"
        android:textColor="#FFFFFF"
        android:textSize="20dp" />

    <EditText
        android:id="@+id/diaET"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:gravity="center_horizontal"
        android:hint="@string/diaET"
        android:inputType="numberDecimal" />

    <TextView
        android:id="@+id/feedTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/feedTitle"
        android:textColor="#FFFFFF"
        android:textSize="20dp" />

    <EditText
        android:id="@+id/feedET"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:gravity="center_horizontal"
        android:hint="@string/feedET"
        android:inputType="numberDecimal" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/numTeeth"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/numTeeth"
        android:textColor="#FFFFFF"
        android:textSize="20dp" />

    <EditText
        android:id="@+id/teethET"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:gravity="center_horizontal"
        android:hint="@string/teethET"
        android:inputType="number" />

    <Button
        android:id="@+id/calcButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/calcButton"
        android:textColor="#123456"
        android:textSize="20sp"
        android:textStyle="bold" />

    <Button
        android:id="@+id/resetButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/resetButton"
        android:textColor="#123456"
        android:textSize="20sp"
        android:textStyle="bold" />
</LinearLayout>

</ScrollView>

You will notice that in the EditText I link to a string value for the hint. Strangely the hints only appear in early SDK but not later ones. This occurs in both the emulator and actual devices.

Rick Shaw
  • 3
  • 4
  • Why are you even using SDK 1.5? No devices are using this version of android i think. See this (http://developer.android.com/resources/dashboard/platform-versions.html) – Shaiful Feb 12 '12 at 07:33
  • @Shaiful - My bad, it is actually SDK3.0 – Rick Shaw Feb 12 '12 at 17:42
  • Using a lower API sometimes can be good in order to make sure that all phones can use your application. This way, even though there is Android fragmentation, all phones will be able to use your application. – Jared Burrows Mar 27 '12 at 19:17

1 Answers1

0

I just answered a very similar question to this as well:

EditText hint not displaying

Here I believe your question has already been solved before, adding certain layouts to the element "EditText" such as "android:gravity="center_horizontal" may cause your problem:

How to add hint into EditText with inputType=“numberDecimal”?

Try removing that and wrap it in a layout that uses "android:gravity="center_horizontal" and put the "EditText" element inside.

Working example on StackOverflow:

Rows don't render properly in Android Layout. Buttons seem to be the problem

Doing a quick Google search here are some examples where people have gotten it to work:

The Android Tutorial Series Part 2 – Calculator App,

unit-testing-with-the-junit-testing-framework,

Android 4 - Apps Mortagage Calculator

I use Android 1.5 in order to make sure that all phones and tablets can run any application I create. Goodluck!

Community
  • 1
  • 1
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
  • Thank you for the guidance. Being new to programming it is easy for me to get lost and overwhelmed. Your suggestion to remove the gravity from the edit text and place into the layout worked perfectly. Much appreciated. Regards, – Rick Shaw Apr 16 '12 at 05:35
  • Thanks for the reply! Its good know people are willing to continue striving to learn new things. Keep going, never give up! – Jared Burrows Apr 16 '12 at 19:57