You problem is, that i
is not the position
of the item in the ArrayList
modules
.
It is the position
of the positive button (which might be 0 or 1 or 2 on every click, no matter which icon; maybe it's -1).
To fix this problem do the following:
Save/use the position
given in onItemClick(AdapterView<?> parent, View view, int position, long id)
and somehow pass it through to the onClickListener()
of the dialog. Use this position to remove an item from your modules
list.
E.g. in onItemClick()
save position
to a filed of your class mClickedPosition
and call modules.remove(mClickedPosition)
in the listener.