tags:

views:

250

answers:

1

Hi, I have a layout which has a button and follow by a ListView. The problem I have with this is when the button has focus (background is orange), and I press DOWN in my keyboard, the first row of the ListView does not have a focus.

     <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

            <ImageButton android:id="@+id/button" style="@android:style/Button"/>

    </LinearLayout>

    <ListView android:id="@+id/action_list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
        />

This is the layout of each row in the ListView:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:focusable="true"
><TextView android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

    />
</LinearLayout>

I have tried using the 'android:nextFocusDown' attribute, but that does not help my problem:

            <ImageButton android:id="@+id/button" style="@android:style/Button"/>

    </LinearLayout>

    <ListView android:id="@+id/action_list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:nextFocusUp="@id/button"
        />

Any idea how to fix this focus problem? I basically want to button move focus to the first row of the ListView when I press DOWN. and the first row of the ListView move focus to the button when I press UP.

Thank you.

A: 

I had the same problem and google to try to found a way to do this, but I just tryed the list_view methods and I fixed this way:

ListView list_view = getListView(); list_view.requestFocus(); list_view.setSelection(0);

You have to set focus in list view, but if you want to appear focused some item, you have to call the setSelection method with the index item that you want selected.

Klaus Magalhães Balduino