在我的Android应用程序中,我想在ListView
添加页脚。
listfooter.xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:gravity="center_horizontal"
android:padding="3dp"
android:layout_height="fill_parent">
<TextView
android:id="@+id/getmore"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:gravity="center"
android:textSize="16dp"
android:textColor="#D61E5C"
android:text="Load More"
android:textStyle="bold"/>
</RelativeLayout>
这是我的 main.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:orientation="vertical" >
<ListView
android:id="@+id/expecters_listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/first_view"
android:layout_marginTop="2dp"
android:divider="#A9A9A9"
android:dividerHeight="0.5dp"
android:fadingEdge="none"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:scrollbarStyle="outsideOverlay"
android:scrollbarThumbVertical="@drawable/scroll_thumb"
android:smoothScrollbar="true" />
</RelativeLayout>
这是我的Activity
课程, MainActivity.java :
public class BestExpectersActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
expecters_listView = (ListView)findViewById(R.id.expecters_listView);
footerView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.listfooter, null, true);
//after getting the result
//set the direct messages to list view
expectersAdapter = new BestExpectersAdapter(BestExpectersActivity.this, remindersResult);
expecters_listView.setAdapter(expectersAdapter);
//set the footer
expecters_listView.addFooterView(footerView);
}
}
列表在某些项目中可见,但页脚不可见(不添加到ListView
)。
答案 0 :(得分:2)
尝试在setAdapter
之前添加页脚,如下面的代码。
//set the footer
expecters_listView.addFooterView(footerView);
expecters_listView.setAdapter(expectersAdapter);
我希望这会对你有所帮助。