这段代码有什么不好的地方吗?
问题是“测试”不会显示在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"
/>发布于 2012-10-29 21:20:59
你试过这个吗?
namesAA = new ArrayAdapter<String> ( this, android.R.layout.simple_list_item_1, android.R.id.text1, names );顺便问一下,你为什么要指定物品的位置?您正在清除数组列表,所以我认为添加names.add("test");会更好。
https://stackoverflow.com/questions/3157157
复制相似问题