Android 在listview下面添加视图
我已经使用ListActivity创建了listview 我想在该列表下面添加另一个视图。那么我该如何做呢? 这里有两个文件spacelist.xml和homescreen.java,我使用它们创建了这个列表Android 在listview下面添加视图,android,listview,Android,Listview,我已经使用ListActivity创建了listview 我想在该列表下面添加另一个视图。那么我该如何做呢? 这里有两个文件spacelist.xml和homescreen.java,我使用它们创建了这个列表 spacelist.xml- <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" a
spacelist.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="70dp"
android:background="@drawable/background"
android:layout_marginBottom="10dp">
<ImageView
android:id="@+id/icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:src="@drawable/ic_launcher" >
</ImageView>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="@+id/label"
android:textSize="20dp" >
</TextView>
</LinearLayout>
homeScreen.java-
public class homeScreen extends ListActivity{
String list[]={"My Ideas","Space1","Space2","All Notes","Create New Space"};
ListView spaces;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//To display as a list
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.spacelist, R.id.label, list);
setListAdapter(adapter);
}
}
spacelist.xml-
homeScreen.java-
公共类主屏幕活动{
字符串列表[]={“我的想法”、“空格1”、“空格2”、“所有注释”、“创建新空格”};
列表视图空间;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
//显示为列表
ArrayAdapter=新的ArrayAdapter(此,
R.layout.spacelist,R.id.label,list);
setListAdapter(适配器);
}
}
现在假设我想在列表下面添加另一个视图。我该怎么做呢?这实际上取决于您想对该视图执行什么操作:始终在列表上方视图的底部可见?或者在列表底部显示该视图可以吗 第一个选项,您可以使用活动(而不是ListActivity)并在布局中执行任何您想要的操作
第二个选项,您可以为listview设置一个页脚,或者在listview中有一个+1项,该项就是您的视图。当然,您必须在适配器中管理不同类型的视图,因此最好设置页脚。您可以通过在listview中添加页脚视图来实现这一点。如果确认,请记住接受答案并投票选择有用的注释;)