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

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

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

Fig1-Footer喜欢“更多新闻”

8469d9b202accb13f38159bf04acbe37.png

c75f8dc30ded096cdb809747866e88de.png

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

6个解决方案

201 votes

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

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

ListView.addFooterView(footerView);

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

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">

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">

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" />

活动类可以是:

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 answered 2019-09-09T08:04:30Z

9 votes

我知道这是一个非常古老的问题,但我在这里搜索并发现答案不是100%令人满意,因为正如gcl1所提到的 - 这样页脚不是屏幕上的页脚 - 它只是一个“附加组件” “到列表中。

底线 - 对于其他可能在这里谷歌的人 - 我在这里找到了以下建议:ListFragment下面的固定且始终可见的页脚

尝试执行以下操作,其中重点是XML中首先列出的按钮(或任何页脚元素) - 然后将列表添加为“layout_above”:

Ofer Lando answered 2019-09-09T08:05:10Z

9 votes

这里的答案有点过时了。 虽然代码保持不变,但行为有一些变化。

public class MyListActivity extends ListActivity {

@Override

public void onCreate(Bundle savedInstanceState) {

TextView footerView = (TextView) ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_view, null, false);

getListView().addFooterView(footerView);

setListAdapter(new ArrayAdapter(this, getResources().getStringArray(R.array.news)));

}

}

有关addFooterView()方法的信息

添加固定视图以显示在列表的底部。 如果多次调用addFooterView(),则视图将按添加顺序显示。 使用此调用添加的视图可以在需要时获得焦点。

上面的大多数答案都非常重要 -

必须在调用setAdapter()之前调用addFooterView().这样ListView可以将提供的光标包装起来,也可以考虑页眉和页脚视图。

来自Kitkat的情况发生了变化。

注意:首次引入时,只能在使用setAdapter(ListAdapter)设置适配器之前调用此方法。 从KITKAT开始,可以随时调用此方法。 如果ListView的适配器没有扩展HeaderViewListAdapter,它将被WrapperListAdapter的支持实例包装。

文档

Aniket Thakur answered 2019-09-09T08:06:17Z

5 votes

如果ListView是ListActivity的子级:

getListView().addFooterView(

getLayoutInflater().inflate(R.layout.footer_view, null)

);

(在onCreate()里面)

Andrey answered 2019-09-09T08:07:04Z

2 votes

您要添加listview页脚的活动,我还在listview页脚单击上生成一个事件。

public class MainActivity extends Activity

{

@Override

protected void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

ListView list_of_f = (ListView) findViewById(R.id.list_of_f);

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View view = inflater.inflate(R.layout.web_view, null); // i have open a webview on the listview footer

RelativeLayout layoutFooter = (RelativeLayout) view.findViewById(R.id.layoutFooter);

list_of_f.addFooterView(view);

}

}

activity_main.xml中

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@drawable/bg" >

android:id="@+id/dept_nav"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@drawable/dept_nav" />

android:id="@+id/list_of_f"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@+id/dept_nav"

android:layout_margin="5dp"

android:layout_marginTop="10dp"

android:divider="@null"

android:dividerHeight="0dp"

android:listSelector="@android:color/transparent" >

Xar E Ahmer answered 2019-09-09T08:08:02Z

0 votes

在这个问题中,最佳答案对我不起作用。 之后我发现这个方法显示listview页脚,

LayoutInflater inflater = getLayoutInflater();

ViewGroup footerView = (ViewGroup)inflater.inflate(R.layout.footer_layout,listView,false);

listView.addFooterView(footerView, null, false);

并创建新的布局调用footer_layout

xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/tv"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Done"

android:textStyle="italic"

android:background="#d6cf55"

android:padding="10dp"/>

如果不工作,请参阅本文

Kusal Thiwanka answered 2019-09-09T08:08:44Z

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值