Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Edittext with gravity center not working on device

In Android I'm using a single line edittext with gravity set to center. In the Emulator this works great both the hint and a blinking cursor shows up. When testing on device (Xperia X10) neither the hint text nor the blinking cursor shows up. The blinking cursor only shows if I enter some text into the edittext.

This is my edittext, can anyone see if something is missing?

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_gravity="center"
>
<EditText 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="numberDecimal" 
    android:ellipsize="end" 
    android:maxLines="1"
    android:gravity="center" 
    android:layout_gravity="center"
    android:hint="Some hint text"
></EditText>
</LinearLayout>

What I want:

This is what I want

What I get with the above code (empty edittext with no cursor):

The edittext doesn't show the hint text and have no blinking cursor

like image 715
Martin Avatar asked May 26 '11 09:05

Martin


1 Answers

I finally found the solution to get it working. This EditText works for me: (Tested on Sony Ericsson X10 and HTC Wildfire)

<EditText 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="numberDecimal" 
    android:digits="0123456789.,"
    android:ellipsize="start" 
    android:maxLines="1"
    android:gravity="center"
    android:hint="Some hint text"
></EditText>
like image 196
Martin Avatar answered Nov 28 '22 17:11

Martin