我正在开发一个应用程序,在我的应用程序中,我使用 Listview 使用 dom 解析来显示数据,我想在 listview 中添加页脚,当我单击页脚时,其他更多数据添加到 ListView ,我附加了图像,我想要那个设计和处理,请引用image1和imgae2。我在红色矩形中提到了页脚
Fig1-像“更多新闻”这样的页脚
图2-在listview中添加额外的10条记录
最佳答案
创建一个包含要设置为页脚的文本的页脚 View 布局,然后尝试
View footerView = ((LayoutInflater) ActivityContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
ListView.addFooterView(footerView);
页脚的布局可能是这样的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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">
<LinearLayout
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">
<TextView
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" />
</LinearLayout>
</LinearLayout>
Activity 类可以是:
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);
}
}
关于android - 如何在 ListView 中添加页脚?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4265228/