如何动态添加页脚视图

发布于 2024-12-06 13:23:24 字数 594 浏览 1 评论 0原文

我创建了一个 ListView 并使用 addHeaderView 添加了标头,然后在我的 ListActivity 中调用了 setListAdapter 。知道如何在调用 setListAdapter 后动态地 addFooterView 吗?

回答: 我将页眉视图和页脚视图(实际上是按钮)添加到列表视图中, 但是我使用wrap_content高度将它们包装到FrameLayout中,然后当我不需要显示标题按钮时,我只需setVisibility(View.GONE)并且FrameLayout包装到0高度并且视觉上它不可见(相同的效果就像我会调用removeHeaderView),如果我需要再次显示它,我设置Visibilty(View.VISIBLE)并显示它(与addHeaderView效果相同 - 这在调用后当然是不可能的设置列表适配器)

此处讨论: 在 ListView 中隐藏页脚视图吗?

I have created a ListView and added header with addHeaderView, then I called setListAdapter in my ListActivity. Any idea how can I dynamically addFooterView after I called setListAdapter?

ANSWER:
I added both header view and footer view (actually buttons) into my list view,
but both of them I wrapped into a FrameLayout using wrap_content height, then when I do not need to be the header button to be shown I just setVisibility(View.GONE) and FrameLayout wraps to 0 height and vissualy it is not visible (same effect as if I would call removeHeaderView), and if I need to show it again I setVisibilty(View.VISIBLE) and it is shown (same effect as addHeaderView - which is of course not possible after calling setting list adapter)

Discussed here:
Hide footer view in ListView?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

锦上情书 2024-12-13 13:23:24
View header = getLayoutInflater().inflate(R.layout.header, null);
View footer = getLayoutInflater().inflate(R.layout.footer, null);
ListView listView = getListView();

listView.addHeaderView(header);
listView.addFooterView(footer);    
setListAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_single_choice,
            android.R.id.text1, names));
View header = getLayoutInflater().inflate(R.layout.header, null);
View footer = getLayoutInflater().inflate(R.layout.footer, null);
ListView listView = getListView();

listView.addHeaderView(header);
listView.addFooterView(footer);    
setListAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_single_choice,
            android.R.id.text1, names));
梦行七里 2024-12-13 13:23:24

你必须这样做

View header = (View)getLayoutInflater().inflate(R.layout.header,null);

SimpleAdapter myAdapter=new SimpleAdapter(this,myList,R.layout.transactionvalues,
new String[] {"transaction_date_time","user_name","site_name","machine_name"},new int[] {R.id.Date_Time,R.id.User,R.id.Site,R.id.Machine});

if(header == null){
    lst.removeHeaderView(header);
}else
{
    lst.addHeaderView(header,null,false);
}

lst.setAdapter(myAdapter);

You Have to do like this

View header = (View)getLayoutInflater().inflate(R.layout.header,null);

SimpleAdapter myAdapter=new SimpleAdapter(this,myList,R.layout.transactionvalues,
new String[] {"transaction_date_time","user_name","site_name","machine_name"},new int[] {R.id.Date_Time,R.id.User,R.id.Site,R.id.Machine});

if(header == null){
    lst.removeHeaderView(header);
}else
{
    lst.addHeaderView(header,null,false);
}

lst.setAdapter(myAdapter);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文