Android开发~ListView

来源:互联网 发布:鸳鸯阵 知乎 编辑:程序博客网 时间:2024/06/06 04:22

1、Your content must have a ListView whose id attribute is 'android.R.id.list'

出现这个问题的场景是新建了Activity,继承自ListActivity,注意XML布局文件和java文件:


XML布局文件:这个文件中要添加一个ListView:

<ListView        android:id="@android:id/list" //注意这个地方的写法        android:layout_width="fill_parent"        android:layout_height="fill_parent" />

java文件:

<span style="font-family:Menlo;font-size:10px;">public class SimpleTableActivity extends ListActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);//        setContentView(R.layout.activity_simple_table); //即使创建Activity时候继承自ListActivity,这行也会出现,不要重新指定view了//        setContentView(getListView()); //这样显示的指定view,没有错,但多余。不过有助于理解,</span><span style="font-family: Menlo; font-size: 10px;">ListActivity 本身定义了一个view,id为list,但还要在XML文件中指定下,愁……</span>


0 0