I am trying to create a button that already has an index captures and just needs to delete from an ArrayList<String> and ArrayList<Integer>. The integer list deletes the index just fine but the string array do not. Code Below:
Globals:
ArrayList<String> QandItem = new ArrayList<String>();
ArrayList<Integer> Prices = new ArrayList<Integer>();
ArrayAdapter<String> left;
ArrayAdapter<Integer> right;
These are setup and filled in the on create method. I know they work correctly because I get output when viewing them on the device.
RemoveItem.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO
if(i >= 0){
QandItem.remove(i);
Prices.remove(i);
left.notifyDataSetChanged();
right.notifyDataSetChanged();
ItemList.setAdapter(left);
PriceList.setAdapter(right);
}
}
});
Where i is the index I am trying to delete.
Since i is an
Integer, you are trying to remove the objectiand not the element at position i. Try usingi.intValue()instead.See the difference between ArrayList.remove(int index) and ArrayList.remove(Object o).