Shuffling an Adapter [duplicate]

霸气de小男生 提交于 2020-08-06 07:01:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!