问题
I am using an Adapter
:
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1);
and I want to shuffle the contents of it, however I discovered that Collections.shuffle(adapter);
does not work. Is there another method to do this? While keeping the format of adapter
i.e. not changing it to a List
回答1:
Of course Collections.shuffle(adapter)
doesn't work..shuffle takes a java.util.List... The Java Collections API knows nothing about the Android API...
You need to shuffle the underlying List and then then tell the adapter that the data has changed..something like:
Collections.shuffle(myList);
adapter.notifyDataSetChanged();
来源:https://stackoverflow.com/questions/15300497/shuffling-an-adapter