我在我的應用程序中使用地圖。一切都很好,除了適配器。我不知道爲什麼它只顯示所有選項卡中的最後一個元素。適配器顯示所有選項卡中的最後一個值
這裏是我的代碼:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<Map<String,String>> list = new ArrayList<Map<String,String >>();
Map<String,String> map = new HashMap<String, String>();
EmployeeDatabase empClick = new EmployeeDatabase(getApplicationContext());
Cursor cursor = empClick.getDetails();
if(cursor.moveToFirst()){
do{
String name = cursor.getString(cursor.getColumnIndex("name"));
String age = cursor.getString(cursor.getColumnIndex("age"));
map.put("name",name);
map.put("age",age);
list.add(map);
}while(cursor.moveToNext());
cursor.close();
}
SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.show_data, new String [] {"name", "age"}, new int[] {R.id.name,R.id.age});
setListAdapter(adapter);
}
創建''HashMap'地圖地圖=新的HashMap ();''裏面如果(cursor.moveToFirst ()){{...}條件。 –
Piyush
2014-09-29 06:19:34
@PG_Android謝謝.. :) – Sangeeta 2014-09-29 07:27:56