这段代码有什么不好的地方吗?
问题是“测试”不会显示在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");会更好。
发布于 2010-07-01 19:09:58
我注意到的第一件事是,layout_height被设置为wrap_content,它不会分配超过绝对需要的高度。对于滚动视图来说,这有点自相矛盾,因为它可以有多小是没有物理限制的。
我猜这就是你的问题所在。
发布于 2013-08-03 17:12:26
如果您使用的是ListActivity或ListFragment,则需要将列表视图的名称更改为: android:id="@+id/android:list“
编辑:哇,我才意识到这个问题已经三年了
https://stackoverflow.com/questions/3157157
复制相似问题