android - 如何在 ListView 中添加页脚?

标签 android android-listview footer

我正在开发一个应用程序,在我的应用程序中,我使用 Listview 使用 dom 解析来显示数据,我想在 listview 中添加页脚,当我单击页脚时,其他更多数据添加到 ListView ,我附加了图像,我想要那个设计和处理,请引用image1和imgae2。我在红色矩形中提到了页脚

Fig1-像“更多新闻”这样的页脚
alt text

alt text

图2-在listview中添加额外的10条记录

最佳答案

创建一个包含要设置为页脚的文本的页脚 View 布局,然后尝试

View footerView = ((LayoutInflater) ActivityContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
ListView.addFooterView(footerView);

页脚的布局可能是这样的:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingTop="7dip"
    android:paddingBottom="7dip"
    android:orientation="horizontal"
    android:gravity="center">

    <LinearLayout 
        android:id="@+id/footer_layout" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center"
        android:layout_gravity="center">

    <TextView 
        android:text="@string/footer_text_1" 
        android:id="@+id/footer_1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textSize="14dip" 
        android:textStyle="bold" 
        android:layout_marginRight="5dip" />
    </LinearLayout>
</LinearLayout> 

Activity 类可以是:

public class MyListActivty extends ListActivity {
    private Context context = null;
    private ListView list = null;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        list = (ListView)findViewById(android.R.id.list);

        //code to set adapter to populate list
        View footerView =  ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
        list.addFooterView(footerView);
    }
}

关于android - 如何在 ListView 中添加页脚?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4265228/

相关文章:

android - 永久修改启动 Activity 的 Intent

android - TextView 内容在 android 4.2.2 上不正确居中

jquery - 随着 jQuery DOM 操作(添加/删除/等)的内容更改,页面页脚在 View 中上下跳动

html - 页脚~定位//扭曲

css - 底部页脚不会在横向模式 iOS 7 中停留

android - 如何创建像 Windows 服务一样运行的 Android 服务?

android - 更改操作栏中的按钮图像

java - 如何获取 onActivityResult 中的上下文?

android-listview - `ListView` 当一些列表项的高度很大时没有滚动到准确的位置

android - 处理游标频繁读取和写入的 ListView 的最佳方法是什么?