Unable to modify ArrayAdapter in ListView: UnsupportedOperationException

I tried it out myself and found it didn’t work, so I checked out the source code of ArrayAdapter and found out the problem: The ArrayAdapter, on being initialized by an array, converts the array into an AbstractList (List<String>) which cannot be modified.

Solution
Use an ArrayList<String> instead using an array while initializing the ArrayAdapter.

String[] array = {"a","b","c","d","e","f","g"}; 
ArrayList<String> lst = new ArrayList<String>(Arrays.asList(array));
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
android.R.layout.simple_list_item_1, lst);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)