我有我的自定义列表视图,在每行的末尾我都有ImageView从列表中删除该行,但是当我点击这个图像时,我得到"Arryindesoutofboundexception:length = 681 indez = -1"
帮我
private OnClickListener imageviewClickListener = new OnClickListener() {
@Override
public void onClick(View v)
{
int index;
index=listView.getSelectedItemPosition();//itemsListView is the listview
dataAdapter.remove(topicsList.get(index));
topicsList.clear();
dataAdapter.notifyDataSetChanged();
}
};
Run Code Online (Sandbox Code Playgroud)
您的项目未被选中,因为图像截取了触摸事件,因此所选位置为-1.为了完成这项工作,您需要告诉OnClickListener它属于哪个项目:
private static class MyClickListener implements OnClickListener {
private final int mIndex;
private MyClickListener (int index) {
mIndex = index;
}
@Override
public void onClick(View v) {
dataAdapter.remove(topicsList.get(mIndex));
topicsList.clear();
dataAdapter.notifyDataSetChanged();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6469 次 |
| 最近记录: |