隐藏自定义微调器列表中的选定项目 [英] Hide the selected item from the custom spinner list

查看:48
本文介绍了隐藏自定义微调器列表中的选定项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个微调器,通过适配器显示一些项目.事情是,每当我单击微调框时,它就会显示用户可选择的所有项目的列表.我想从列表中隐藏当前选中的项目.

I have a Spinner displaying some items via an Adapter. The thing is everytime I click on the spinnerm it shows the list of all items that are selectable by the user. I would like to hide the item currently selected from the list.

这是我的物品清单:

已选择:项目A

纺锤列表:

  • 项目A
  • 项目B
  • 项目C

如果我选择项目B,它将变为:

If I select Item B, it will become:

已选择:项目B

纺锤列表:

  • 项目A
  • 项目B
  • C项

我想隐藏微调框列表中的选定项目.因此,在前两种情况下:

I would like to hide the selected item from the Spinner List. So, in the two previous cases:

已选择:项目A

纺锤列表:

  • 项目B
  • C项

如果我选择项目B,它将变为:

If I select Item B, it will become:

已选择:项目B

纺锤列表:

  • 项目A
  • 项目C

推荐答案

您应该创建一个列表项.因此,每次选择一个项目时,您都将其放在此列表中.之后,您将比较两个列表:一个具有所有值的列表,一个具有选定值的列表,并仅显示尚未选择的项目. 我已经用过这样的东西:

You should create a list of seleted items. So everytime you select an item, you put on this list. After that you compare the two lists: the one with all values, with the one with the selected values and display only the items that aren't already selected. I've already used something like this:

    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);
    }

我希望对您有帮助

这篇关于隐藏自定义微调器列表中的选定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆