我正在使用 ListActivity 来设置我的 ListView 。我想做的是在上部显示 ListView ,在父级底部显示线性布局。
因为我使用的是 ListActivity,所以我没有布置任何布局文件。我设法做的仍然是获取 listview 实例,但是当我尝试在 linearLayout 中设置它时,出现错误:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first
我正在使用以下代码:
final ListView lv = getListView();
LinearLayout root = new LinearLayout(this);
root.setOrientation(LinearLayout.VERTICAL);
root.setLayoutParams(new LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT));
root.addView(lv);
setContentView(root);
最佳答案
您应该在 ListActivity 中使用自定义布局。
这是一个教程:http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/
关于android - 在 ListActivity android 中添加 ListView 和线性布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4863722/