android - 将焦点从按钮移动到 ListView 时出现问题

标签 android

我有一个布局,其中有一个按钮,后面是一个 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/

相关文章:

android - OnTouchListener 的 Ontouch 事件在 android 中被调用两次

android - 单击按钮时如何动态添加编辑文本框?

android - 迁移到 Android Studio 1.5 后任务 ':tess-two:processReleaseResources' 执行失败

android - 如何更改 Actionbar 背景的显示方式?

java - Android widget 的固定更新频率

android - 在 cygwin 中编译 ocr 代码时,有人可以帮助我获得解决方案吗?

java - 如何使用zip4j和outputstream压缩文件夹和子文件夹

android - Glide 库 java.lang.NoClassDefFoundError

Android - 将图像文件合并到电影中(但不使用 JMF)

java - 如何使用 Java 正则表达式在 Android 上验证用户名和密码?