【发布时间】:2012-06-07 15:17:42
【问题描述】:
我有一个位置列表
ArrayList<Location> locationList;
每个位置都包含名称、地址、描述等信息... 我只想在每一行中显示名称,以便您可以选择要在新意图中接收更多信息的位置。
我设法使用以下代码在 ListView 中显示字符串:
locationNames= new String[]{"I","am", "a", "ListView"};
setListAdapter(new ArrayAdapter<String>(this, R.layout.singleitem,
locationNames));
ListView locationListview;
locationListview = getListView();
locationListview.setTextFilterEnabled(true);
到目前为止,这有效,但我无法在此 listView 中显示列表的内容,也无法询问有关单击行的更多信息。
我考虑读取列表的第一个元素以将它们保存在字符串数组中。 当您想要单击它们以获取更多信息时,这会导致问题。
最好的方法是什么?
真诚地, 沃尔芬
【问题讨论】:
-
您如何获得(或构建)
locationList?有内置的适配器(如用于光标的 SimpleCursorAdapter)可以快速完成这项工作,或者您可以编写自定义适配器。
标签: android list listview arraylist