I have a ArrayList tokens; I am adding values to the array with a listView click. Before i add the value to array i check if the value already exist array. I remove the value is it exists else i will add the the value
This is how i have done, but the values are not being added to the array
ArrayList<String> tokens;
tokens = new ArrayList<String>();
...
....
public void onItemClick(AdapterView<?> listView, View view,
int position, long id) {
Cursor cursor = (Cursor) listView.getItemAtPosition(position);
String selectedtoken = cursor.getString(cursor.getColumnIndexOrThrow("ContactToken"));
for (int i = 0; i < tokens.size(); i++) {
if (tokens.get(i).equals(id_To_Search)) {
tokens.remove(i);
}
else {
tokens.add(selectedtoken );
}
}
}
...
...
Log.i("array: ", tokens.toString()); // No values in the array