Android 如果ListView中没有项目,则ListView.addFooterView()不工作
我正在使用将页脚添加到listviewAndroid 如果ListView中没有项目,则ListView.addFooterView()不工作,android,xml,listview,android-listview,Android,Xml,Listview,Android Listview,我正在使用将页脚添加到listview View footerview = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_social, null, false); listview_followers.addFooterView(footerview); 这是我的xml列表视图 <ListView android:i
View footerview = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_social, null, false);
listview_followers.addFooterView(footerview);
这是我的xml列表视图
<ListView
android:id="@+id/listview_followers"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
和footerview xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btnSend_social"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/botao_bgg"
android:text="SEND"
android:textColor="#ffffff"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
如果listview中有项目,则已成功添加footerview.xml。如果listview中没有项目,也不会显示footerview
有人能帮忙吗 我认为不可能在空的
列表视图中添加页脚。尽管列表视图
可以使用空的视图
,当列表视图中没有项目时,可以显示该视图。现在有两种方法可以做到这一点:
1:
2:
此处的empty
属于View
类型,因此它可以是LinearLayout
或RelativeLayout
,可以在运行时使用LayoutInflater
对其进行充气
注意:确保在添加空视图后设置适配器
希望有帮助。建议:您可以为listview创建单独的布局,并将页脚包含在listview xml文件中。然后,我确信即使listview为空,页脚也会显示。@kgandroid Yeh,但main.xml+footerview.xml有大量内容,因此我已将setOnTouchListener应用于listview,以便它可以滚动它不是工作伙伴,listview_followers.setEmptyView(footerview);视图页脚视图=((LayoutInflater)getSystemService(Context.LAYOUT\u INFLATER\u SERVICE)).inflate(R.LAYOUT.footer\u social,null,false)@Prince在给列表视图充气之前,一定要先充气footerView
,很抱歉,我没有抓住你。像个魔咒一样工作:D:D
RelativeLayout empty = (RelativeLayout) getLayoutInflater().inflate(
R.layout.empty_view,
null);
((ViewGroup)list.getParent()).addView(empty);
list.setAdapter(adapter);
RelativeLayout empty = (RelativeLayout) getLayoutInflater().inflate(
R.layout.empty_view,
(ViewGroup) list.getParent());
list.setEmptyView(empty);