改组适配器 [英] Shuffling an Adapter
问题描述
我正在使用Adapter
:
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1);
,我想将其内容改组,但是我发现Collections.shuffle(adapter);
不起作用.还有另一种方法可以做到这一点吗?保留adapter
的格式,即不将其更改为List
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
推荐答案
当然Collections.shuffle(adapter)
不起作用..shuffle需要一个java.util.List ... Java Collections API对Android API一无所知. ..
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();
这篇关于改组适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!