安卓 ListView中点击事件获取Item中的对象

时间:2022-08-11 22:40:20
注明:
ListView的对象 : mListView
继承于BaseAdapter自定义的adapter
ResultItem:每个Item数据的类
private ListView mListView;private List<ResultItem> arrResults;private MyAdapter adapter;
</pre><pre>
mListView.setOnItemClickListener(new OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> parent, View view,int position, long id) {ResultItem item=(ResultItem) adapter.getItem(position);Toast.makeText(getActivity(), "你点击了第" + item.getDate() + "项!",Toast.LENGTH_SHORT).show();}});


关键代码 adater.getItem(Position)