我遇到了在列表视图中获取所选数组列表项的问题。 这是我的代码:
ArrayList<Doctor> doctorList = new ArrayList<Doctor>();//this is the resources of my List.
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, doctorList));
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
LinkedHashMap<String, Object> obj = new LinkedHashMap<String, Object>();
Doctor aDoc=(Doctor)l.getItemAtPosition(position);//this line show error
obj.put("hashmapkey", aDoc);
Intent inew = new Intent(DoctorsListActivity.this,
DoctorBioDataActivity.class);
Bundle b = new Bundle();
b.putSerializable("bundleobj", obj);
inew.putExtras(b);
startActivity(inew);
}`
* 我只是获取所选的数组列表项对象以传递下一个活动* 请帮忙..
答案 0 :(得分:3)
而不是使用
Doctor aDoc=(Doctor)l.getItemAtPosition(position);
使用您的ArrayList doctorList;
从中获取Object
,如下所示:
Doctor aDoc = doctorList.get(position);