如何在 ListView 中添加页脚?

新手上路,请多包涵

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

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

替代文字

替代文字

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

原文由 JohnNick 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 509
2 个回答

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

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>

活动类可以是:

 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);
    }
}

原文由 Shaireen 发布,翻译遵循 CC BY-SA 3.0 许可协议

   // adding a footer to list as Log Out
    val view: View =
        (getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater).inflate(
            R.layout.logout_menu, null, false
        )
    //  footer onClick
    view.setOnClickListener {
        doLogout()
        binding.drawerLayout.close()

    }
    expandableListView.addFooterView(view)

原文由 Rajnish Kumar Tripathi 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题