Android 如何更新适配器?
我一个班有几个纺纱工。 对于第一个微调器,我有一组数据。 其他Spiner将根据First Spiner的选择从服务器下载数据。 但是,下载数据后,它不会更新微调器适配器 第二个微调器的适配器:Android 如何更新适配器?,android,adapter,android-arrayadapter,Android,Adapter,Android Arrayadapter,我一个班有几个纺纱工。 对于第一个微调器,我有一组数据。 其他Spiner将根据First Spiner的选择从服务器下载数据。 但是,下载数据后,它不会更新微调器适配器 第二个微调器的适配器: sectionField = new String[] {"Error"}; adapterSection = new ArrayAdapter<String>( this, android.R.layout.simple_sp
sectionField = new String[] {"Error"};
adapterSection = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, sectionField);
adapterSection
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
section.setAdapter(adapterSection);
您需要清理适配器,然后添加项目并通知
adapterSection.clear();
adapterSection.addAll(data);
adapterSection.notifyDataSetChanged();
希望对您有所帮助。
adapterSection.clear();adapterSection.addAll(数据)代码>所以数据
没有元素…现在可以工作了,谢谢。需要指出的是,adapter.clear()仅在向adapter提供任何类型的列表时才起作用吗?将您的评论作为答案发布,您在“阅读评论”技能中获得第一名+1。。。而且+2在“将其他用户评论改写为答案”技巧中。。。你已经升到了下一个级别<代码>adapterSection.notifyDataSetChanged()代码>?为何它已在addAll
中调用。。。
adapterSection.clear();
adapterSection.addAll(data);
adapterSection.notifyDataSetChanged();