21

Possible Duplicate:
Stop EditText from gaining focus at Activity startup?

I have two edit text and the first one always has focus. I tried clearFocus() but it doesn't work.

The xml is this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<EditText
    android:id="@+id/barcode"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/enterbarcode" >
</EditText>

<View
    android:layout_width="fill_parent"
    android:layout_height="10dp" >
</View>

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="@string/or"
    android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>

<View
    android:layout_width="fill_parent"
    android:layout_height="10dp" >
</View>

<EditText
    android:id="@+id/name"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="@string/entername" >
</EditText>

<Button
    android:id="@+id/ok"
    android:layout_width="fill_parent"
    android:layout_height="60dp"
    android:background="@drawable/button"
    android:text="@string/forward"
    android:textStyle="bold" >
</Button>

</LinearLayout>

I've read an answer here about a dummy item but I don't know how to apply it to my particular xml.

Community
  • 1
  • 1
Luís Jesus
  • 1,628
  • 5
  • 21
  • 33
  • Sorry, I cannot help. But I do suggest using the android:hint over android:text on your textedits. Then the user will not have to backspace the exsiting contents and you will not have to code an on focus set value to ""; - Plus it keeps in line with the rest of the platform. – rabbitt Jul 06 '11 at 02:57

0 Answers0