我正在使用带有部分的 ListView。我有一个 ArrayAdapters 列表,每个部分一个。我需要在 onItemClick 上确定正确的适配器以在适配器中启动方法。如何获得对正确适配器的引用?
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id)
{
adapterList.get(x).toggleBought(position);
//need to determine x (the x'th adapter in the list
//or somehow get a reference to the adapter instead of adapterList.get(x)
}
这是创建适配器列表的代码:
adapterList = new ArrayList<CartRowAdapter>(); //list of ArrayAdapters
oListAdapter = new CartListAdapter(getActivity()); //BaseAdapter
for (int i = 0; i < cartLists.size(); i++)
{
adapterList.add(new CartRowAdapter(getActivity(), R.layout.cart_row,
cartLists.get(i)));
oListAdapter.addSection(cartLists.get(i).get(0).getAisle(),
adapterList.get(i));
}
listView.setAdapter(oListAdapter);