【发布时间】:2014-10-08 13:55:03
【问题描述】:
我有一个扩展 ListActivity 的课程。里面有 3 个按钮和一个列表视图(可点击项目),列表项目和 2 个按钮工作正常,但一个不响应点击(它的创建方式与其他按钮完全相同)。我认为这与按钮的可聚焦性有关,我已经尝试过 android:focusable="true" 和 "false" 但没有任何变化。
这是我的 xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@android:id/list"
android:layout_below="@+id/checkall"
android:layout_width="match_parent"
android:layout_height="400dp" >
</ListView>
<Button
android:id="@+id/checkall"
android:layout_height="38dp"
android:layout_width="wrap_content"
android:layout_marginLeft="19dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:text="Seleccionar todos"
android:background="#D1D1D1" />
<Button
android:id="@+id/uncheckall"
android:layout_height="38dp"
android:layout_width="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/checkall"
android:layout_alignParentTop="true"
android:text="Borrar selección"
android:background="#D1D1D1"
android:layout_alignParentRight="true" />
//this is the one not accepting clicks -->
<Button
android:id="@+id/mostrar"
android:layout_height="49dp"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:text="Mostrar en mapa"
android:background="#D1D1D1" />
</RelativeLayout>
【问题讨论】:
-
在所有按钮中添加 android:clickable="true" android:focusable="false" 试试这个
-
请告诉我在我的情况下发生了什么,它已经奏效了
-
我在任何地方都看不到 onClick="..."。你如何指定什么被调用?您是否为最后一个按钮指定它?
-
您是为所有 3 个按钮 还是只为 2 个按钮设置点击监听器?
-
你能在点击监听器上显示你的第三个按钮