获取listview上选定的arraylist自定义对象项以传递另一个活动?

时间:2012-09-10 10:30:16

标签: android object

我遇到了在列表视图中获取所选数组列表项的问题。 这是我的代码:

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);
    }`

* 我只是获取所选的数组列表项对象以传递下一个活动* 请帮忙..

1 个答案:

答案 0 :(得分:3)

而不是使用

Doctor aDoc=(Doctor)l.getItemAtPosition(position);

使用您的ArrayList doctorList;从中获取Object,如下所示:

Doctor aDoc = doctorList.get(position);