我有一个布局,其中有一个按钮,后面是一个 ListView。我遇到的问题是当按钮有焦点(背景为橙色)时,我在键盘上按下 DOWN,ListView 的第一行没有焦点。
<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"
/>
这是 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>
我尝试过使用“android:nextFocusDown”属性,但这对我的问题没有帮助:
<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"
/>
知道如何解决这个焦点问题吗?当我按下 DOWN 时,我基本上想将焦点移到 ListView 的第一行。当我按下向上键时,ListView 的第一行将焦点移动到按钮。
谢谢。
最佳答案
你试过focusChangeListener吗? ?
请试穿。那个 Button 的监听器,当它发生变化时,将代码放在 ListView 上
e.g. yourListView.requetFocus();
如果有任何疑问,请告诉我。
关于android - 将焦点从按钮移动到 ListView 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1765932/