listview页脚动态改变状态android
我有 ListView
并且我想添加页脚。我通过标准 addFooterView
方法轻松完成了此操作。但是页脚添加到 ListView
的末尾并显示为 ListView
的一部分(即,如果 ListView
项目更多然后放置在屏幕上,则页脚位于屏幕之外).
为什么我需要它:我想在用户与ListView
中的某些View
交互时显示按钮。并在上“抬起”屏幕底部的
。ListView
边框(当前高度值 - 按钮的高度值)
问题是:适配器中的onClickListener
需要View
。以及 Activity 中的setContentView
。我无法访问从适配器到 ListActivity
的按钮参数。
我的 XML 布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/watchAddList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:listSelector="@drawable/list_selector"
style="@style/listViewStyle">
</ListView>
<include
layout="@layout/submit"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
并包括布局:
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:id="@+id/rl_submit">
<Button
android:id="@+id/submit"
android:layout_height="wrap_content"
android:text="Сохранить"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"></Button>
</RelativeLayout>
UPD: 我做到了!我使用 Singleton,并在 Adapter 类中调用 Activity 实例,然后访问按钮属性。凉爽的!
I have ListView
and I want add footer. I easily did it through standard addFooterView
method. But footer added into end of ListView
and displayed as part of ListView
(i.e. if ListView
items more then placed on the screen then footer outside the screen).
Why I need it: I want show button when user interacted with some View
in ListView
. And "lift up" ListView
border at bottom of screen on (current height value - height value of button)
.
The problem is: onClickListener
required View
in adapter. And setContentView
in Activity. I do not get access to the parameters of a button from the adapter to ListActivity
.
My XML Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/watchAddList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:listSelector="@drawable/list_selector"
style="@style/listViewStyle">
</ListView>
<include
layout="@layout/submit"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
And include Layout:
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:id="@+id/rl_submit">
<Button
android:id="@+id/submit"
android:layout_height="wrap_content"
android:text="Сохранить"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"></Button>
</RelativeLayout>
UPD: I do It! i used Singleton, and call Activity
instance in Adapter
class, then got access to the button properties. Cool!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论