如何动态地更改纱厂的内容 [英] How to change the content of Spinners dynamically

查看:107
本文介绍了如何动态地更改纱厂的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经把4纱厂在 SlidingDrawer 。我已经创造了string.xml一个字符串数组,像

I have placed 4 spinners in a SlidingDrawer. And I have created a string-array in string.xml, like

<string-array name="colorArray">
        <item>Red</item>
        <item>Green</item>
        <item>Blue</item>
        <item>Orange</item>
        <item>While</item>
        <item>Black</item>
</string-array>

我想这个数组来填充纺纱..

I want to populate the spinners with this array..

对于我有过做,

    option1 = (Spinner)findViewById(R.id.spinner_first);
    adapter = ArrayAdapter.createFromResource(getApplicationContext(), 
            R.array.colorArray, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    option1.setAdapter(adapter);

和同为其他3现在工作正常,我。现在的结果是一样,整个阵列上所有的纺织上市。

and the same for the other 3. It works fine for me now. Now the result is like, the entire array is listed on all the spinners.

但我要删除一个微调所有其他纱厂选择的项目,这样,在其他3个。例如,如果我选择红色为第一微调,该项目未显示该项目红必须从所有其它纺纱厂被删除。

But i want to remove the item selected by one spinner in all the other spinners, so that that item is not shown in the other 3.. For example, if i select "red" for the first spinner, the item "Red" must be removed from all other spinners..

那怎么可以实现的。

样codeS和指导,将AP preciable ..
在此先感谢..

Sample codes and guidance will be appreciable.. Thanks in advance..

推荐答案

在您的 onItemSelected()的的的 OnItemSelectedListener 的的的微调的,你需要做的其他的纱厂每个人以下的:

In your onItemSelected() for the OnItemSelectedListener for the Spinner, you need to do the following for each one of the other Spinners:

Spinner spinner; // Each one of the other spinners
String item; // Item selected in the current spinner

// Get the adapter for the other spinner
ArrayAdapter<CharSequence> array = spinner.getAdapter();
// Remove selected element in the current spinner from adapter
array.remove(item);
// Set adapter again
spinner.setAdapter(array);

很抱歉,但我没有(也不可能)测试...

Sorry but I didn't (and can't) test it...

这篇关于如何动态地更改纱厂的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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