Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

requestFocus skipping next EditText

I'm having some problems with the control focusing. My interface definition below has:

source (RadioGroup/optional) destination (EditText) quantity (EditText) transfer (Button)

I'm changing the visibility of the "source" into my code. When the times I don't display it, focus is automatically goes to "quantity" which I would expect that to be "destination" instead. I don't know what I'm missing. I suspect it could be an Android bug, I don't know. Is there anybody know how to solve this?

Thanks

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

    <RadioGroup android:id="@+id/source"
     android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:orientation="vertical"
   android:visibility="gone">
   <RadioButton android:id="@+id/default"
    android:checked="false"
    android:text="@string/default"/>
 </RadioGroup>

 <TableLayout
  android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:stretchColumns="1">
     <TableRow>
   <TextView 
    android:text="@string/destination"
    android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textSize="16sp"
       android:textColor="#ffffff"
       android:paddingRight="10sp"
       android:layout_weight="1"/>

      <EditText android:id="@+id/destination"
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"
       android:layout_weight="1"
       android:singleLine="true"><requestFocus/></EditText>
  </TableRow>

  <TableRow>
   <TextView 
    android:text="@string/quantity"
    android:layout_width="wrap_content" 
       android:layout_height="wrap_content"
       android:textSize="16sp"
       android:textColor="#ffffff"
       android:paddingRight="10sp"
       android:layout_weight="1"/>

      <EditText android:id="@+id/quantity"
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"
       android:layout_weight="1"
       android:singleLine="true"/>
  </TableRow>
 </TableLayout>

 <Button android:id="@+id/transfer"
  android:layout_width="fill_parent" 
     android:layout_height="wrap_content"
     android:text="@string/transfer"/>
</LinearLayout>
like image 366
pocoa Avatar asked Nov 18 '10 05:11

pocoa


4 Answers

It appears to be a known issue. The following post on google code for the Android project describes the same problem.

Issue 2705: Setting requestFocus on EditText prevents soft keyboard from opening

You could try setting focus in your code instead of in the layout.

like image 97
Thomas Avatar answered Sep 22 '22 10:09

Thomas


I faced same issue , Try this code that worked for me.

             editText.post(new Runnable() {
                 public void run() {
                       editText.requestFocus(); 
                                   } 
                                           }); 
like image 22
Parag Chauhan Avatar answered Sep 26 '22 10:09

Parag Chauhan


From online documentation:

A view will not actually take focus if it is not focusable (isFocusable() returns false), or if it is focusable and it is not focusable in touch mode (isFocusableInTouchMode()) while the device is in touch mode.

like image 38
StenaviN Avatar answered Sep 25 '22 10:09

StenaviN


Use EditText's requestFocus() method. :)

like image 36
Shamitha Avatar answered Sep 23 '22 10:09

Shamitha