我正在开发一个应用程序以获取附近的加油站并将它们显示在列表中,我的问题是将它们显示在列表中,我经历了许多教程,但无法弄清楚问题是没有列表出现与数据我相信这部分的问题,但不知道如何解决它,并确保在这个问题,我试图把进展对话,并直接解雇它之前这部分码。ArrayList无法在列表视图中显示 - android
这里使用的适配器,显示数组列表我从onPostexecute
protected void showItems(ArrayList<HashMap<String,String>> placestoList2){
ListAdapter adapter101 = new SimpleAdapter(MainActivity.this, placestoList2,
R.layout.list_item,
new String[] { KEY_NAME, KEY_VICINITY}, new int[] {
R.id.name, R.id.vicinty });
lv.setAdapter(adapter101);
}
调用该方法,并且此方法从列表中我得到的地方
protected ArrayList<HashMap<String,String>> getLocations(List<HashMap<String,String>> list){
for(int i=0;i<list.size();i++){
HashMap<String, String> mapM = list.get(i);
HashMap<String, String> mapM2 = new HashMap<String, String>();
String name = mapM.get("place_name");
mapM2.put(KEY_NAME, name);
String vicinity = mapM.get("vicinity");
mapM2.put(vicinity, vicinity);
placesListItems.add(mapM2);
}
return placesListItems;
}
和清单数据在布局中查看
<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
其他布局
<TextView android:id="@+id/name"
android:visibility="gone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/vicinty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:textStyle="bold"
android:textSize="16sp"/>
你是什么意思“但不知道问题?”你的代码在做什么或者不在做你希望发生或者不发生的事情? – MarsAtomic
请参阅我编辑的问题 –