【发布时间】:2015-05-20 13:29:04
【问题描述】:
我正在使用 ViewGroup 在列表视图中显示我的页脚的 android 应用程序。现在我想为该视图组创建一个侦听器事件,以便用户可以按下该页脚。下面给出了我制作该页脚和视图组的代码以及 xml。
ViewGroup footer = (ViewGroup) getLayoutInflater().inflate(R.layout.footer_view, mListView, false);
View header = getLayoutInflater().inflate(R.layout.footer_view, null);
Button headerButton = (Button)header.findViewById(R.id.footerRefreshBtn);
mListView.addFooterView(footer);
headerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "I am clicked", Toast.LENGTH_LONG).show();
}
});
// It is not showing toast message on click.
页脚的 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:orientation="vertical" >
<Button
android:id="@+id/footerRefreshBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:layout_gravity="center_horizontal"
android:text="Refresh Button"
android:textColor="@color/white"
android:background="@color/gray" />
</LinearLayout>
【问题讨论】:
-
@XaverKapeller 感谢您的回复。我正在使用上面的代码,但视图组不可点击。当我点击它时没有任何反应。请在这里帮助我
-
你为什么使用
addFooterView(View, Object, boolean)?只需使用addFooterView(View)。我认为这是错误的根源。或者更具体地说是最后的false,但我不确定,试试addFooterView(View)。 -
@XaverKapeller 感谢您的回复。请看我上面编辑的代码,我已经按照你的说明进行了更改,但仍然无法正常工作。
标签: android android-listview android-viewgroup