【发布时间】:2011-05-26 18:39:22
【问题描述】:
我有以下布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:text="Height"
android:layout_height="wrap_content"
android:id="@+id/buttonHeight"
android:layout_width="wrap_content"
android:layout_weight="15"
android:onClick="OnClickHeight">
</Button>
<Button
android:text="Width"
android:layout_height="wrap_content"
android:id="@+id/buttonWidth"
android:layout_width="wrap_content"
android:layout_toRightOf="@id/buttonHeight"
android:layout_weight="1"
android:onClick="onClickWidth">
</Button>
</LinearLayout>
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="1px"
android:drawSelectorOnTop="false"/>
</RelativeLayout>
然后我有一个扩展 ListActivity 的类,其中我有我的 onClickWidth 和 onClickHeight 方法,例如:
public void onClickWidth(View v)
{
// does stuff
}
但是,这些 onClick 事件并未得到处理。如果我将类更改为扩展 Activity,而不是 ListActivity,并从我的布局中删除 ListView,然后它被检测到!
我曾尝试设置 android:clickable="true"、使用 android:focusable 属性和其他各种东西,但我就是无法让它工作。我该如何解决这个问题,还是根本不允许这样做?
【问题讨论】:
标签: android listview button onclick listactivity