0
我已經使用下面給出的代碼填充了listview,但是我無法從列表中取回值,因爲getadpter編寫了一個對象。從對象中我無法獲得逐個列值。需要在Android的Listview中從getadapter獲取逐列值
代碼填充列表視圖:
String pkManifest = manifest.pkManifestNo;
ArrayList<HashMap<String, String>> alist = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
manifest_helper = new manifest_helper(this);
cursor = manifest_helper.GetDeliveriesAgainstManifest(pkManifest);
cursor.moveToFirst();
for (int i = 0; i < cursor.getCount(); i++) {
map = new HashMap<String, String>();
map.put("Deliv_Address",
cursor.getString(cursor.getColumnIndex("Address")));
map.put("Deliv_Time",
cursor.getString(cursor.getColumnIndex("Time")));
map.put("Deliv_Order",
cursor.getString(cursor.getColumnIndex("DeliveryOrder")));
map.put("Deliv_IsCustomerPickup",
cursor.getString(cursor.getColumnIndex("IsCustomerPickup")));
map.put("Deliv_FKDeliveryStatus",
cursor.getString(cursor.getColumnIndex("FKDeliveryStatus")));
map.put("Deliv_PKDelivery",
cursor.getString(cursor.getColumnIndex("PKDelivery")));
alist.add(map);
cursor.moveToNext();
}
sd = new SimpleAdapter(this, alist, R.layout.deliveries_list_row,
new String[] { "Deliv_Address", "Deliv_Time",
"Deliv_Order", "Deliv_IsCustomerPickup",
"Deliv_FKDeliveryStatus", "Deliv_PKDelivery" },
new int[] { R.id.tv_Deliv_Address, R.id.tv_Deliv_Time,
R.id.tv_Deliv_Order,
R.id.tv_Deliv_IsCustomerPickup,
R.id.tv_Deliv_FKDeliveryStatus,
R.id.tv_Deliv_PKDelivery });
//selectedAdapter = new SelectedAdapter(this, 0, alist);
//selectedAdapter.setNotifyOnChange(true);
ListDeliveries.setAdapter(sd);
代碼用於獲取關於onItemSelected值是這樣寫的:
private OnItemSelectedListener mDeviceSelectedListener = new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> av, View v, int arg2,long arg3) {
Object o = av.getAdapter().getItem(arg2);
String keyword = o.toString();
MessageBox("You selected: " + keyword);
}