[英]Hide the selected item from the custom spinner list
我有一个微调器,通过适配器显示一些项目。 事情是,每当我单击微调框时,它就会显示用户可选择的所有项目的列表。 我想隐藏当前从列表中选择的项目。
这是我的物品清单:
已选:项目A
微调列表:
如果选择项目B,它将变为:
已选择: B项
微调列表:
我想从微调器列表中隐藏选定的项目。 因此,在前两种情况下:
已选:项目A
微调列表:
如果选择项目B,它将变为:
已选:项目B
微调列表:
您应该创建一个已选中项目的列表。 因此,每次选择一个项目时,您都将其放在此列表中。 之后,您将比较两个列表:一个具有所有值的列表,一个具有选定值的列表,并仅显示尚未选择的项目。 我已经用过这样的东西:
ArrayList<String> allItems = new ArrayList<String>();
ArrayList<String> selectedItems = new ArrayList<String>();
allItems.add("item a");
allItems.add("item b");
allItems.add("item c");
selectedItems.add("item a");
ArrayList<String> auxList = new ArrayList<String>();
//populate an aux list without the selected items
for(String itemFromAll: allItems){
for(String selectedItem: selectedItems){
if(!itemFromAll.equals(selectedItem)){
auxList.add(itemFromAll);
}
}
}
//print the new list without the selected items
for(String newItem: auxList){
System.out.println(newItem);
}
希望对您有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.