【发布时间】:2011-03-10 14:05:09
【问题描述】:
这段代码有什么问题吗?
问题是ListView中没有显示“测试”。
Java:
private ListView namesListView;
private ArrayList<String> names;
private ArrayAdapter<String> namesAA;
...
namesListView = (ListView)findViewById(R.id.list);
names = new ArrayList<String>();
names.clear();
names.add(0, "test");
namesAA = new ArrayAdapter<String> ( this, android.R.layout.simple_list_item_1, names );
namesListView.setAdapter(namesAA);
...
XML:
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
【问题讨论】:
-
java代码在
onCreate方法里面? -
这是一个活动还是一个列表活动?
-
不需要在此处清除名称数组列表,因为您已经分配它并且在清除后,此代码是否在 onCreate 方法中?