Android 在列表活动列表视图中添加了页脚视图,但未显示

Android 在列表活动列表视图中添加了页脚视图,但未显示,android,listview,Android,Listview,我有一个用于页脚视图的xml文件,里面有一个文本视图,我膨胀了页脚视图并从中提取了文本视图,然后我将其作为页脚视图添加到列表活动的列表视图中,但在运行时它不会显示。代码如下: LayoutInflater inflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.footer_view, null); TextView foo

我有一个用于页脚视图的xml文件,里面有一个文本视图,我膨胀了页脚视图并从中提取了文本视图,然后我将其作为页脚视图添加到列表活动的列表视图中,但在运行时它不会显示。代码如下:

LayoutInflater inflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View view = inflater.inflate(R.layout.footer_view, null);
TextView footer=(TextView) view.findViewById(R.id.footer);
getListView().addFooterView(footer); 
以下是xml文件内容:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/footer_text"
android:textColor="#0000FF"
android:textSize="20sp" />

怎么了

尝试添加页脚视图,如下所示:

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
TextView footer = (TextView) inflater.inflate(R.layout.footer_view, getListView(), false);
getListView().addFooterView(footer); 
更新:刚刚查看了我在一个项目中是如何做到这一点的,所以这也应该是可行的:

TextView footer = (TextView) getLayoutInflater().inflate(R.layout.footer_view, getListView(), false);
getListView().addFooterView(footer);

在调用setAdapter之前,请确保调用addFooterView。谢谢:非常感谢:这也是正确的,但Karakuri的回答解决了问题: