我已经用这种方式通过适配器添加了一些列表项。
classStudentsCollection.add(new mClassStudents(R.drawable.ic_profile, "DataOne", "DataTwo", "DataThree"));
我有一个侦听器,用于侦听任何列表项上的单击事件。
classStudentsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(mainAppContext, "position" + position + "id "+id, Toast.LENGTH_SHORT).show();
//get data associated with this particular list object
}
});
现在我想检索与这个mClassStudents
列表对象关联的所有数据,也就是检索值"DataOne", "DataTwo", "DataThree"
。
我该怎么做呢?
1条答案
按热度按时间toiithl61#
若要检索单击的对象,只需调用
并将返回值强制转换为特定对象。如果创建了自定义适配器,则为了正常工作,getItem必须返回与强制转换的项相同的项