如何将微调器中的特定项设置为禁用状态

时间:2014-07-16 06:44:57

标签: android

如果选择了特定项目,我目前设法禁用我的微调器,但是我还想在视觉上将该特定项目设置为disabled状态。这可能吗?

编辑:澄清一下,当我点击我的微调器时,我看到一个下拉菜单,其中包含我可以选择的几个项目。我希望禁用的项目具有不同的视觉效果,如上面的链接。

private static final String[]paths = {"None", "Arrow Rain", "Restoration", "Ares' Fervor", "Windstorm", "Guardian Angel", "Meteor", "Disaster", "Ares' Frenzy", "Phoenix Flight", "Snowstorm"};


ArrayAdapter<String>adapter1 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,paths) {

    @Override      
    public boolean isEnabled(int position) {
        global1 = position;

           if( (global1 == global2 || global1 == global3 || global1 == global4) && global1>0 ){

               return false;
           }else{
               g1t.setText( "Price: " + String.valueOf(g1p) +"\n" );
               totalprice.setText( "Total Price: " + String.valueOf(g1p+g2p+g3p+g4p));
               return true;
           }               
     }
};

magic1 = (Spinner)findViewById(R.id.spinnermagic1);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
magic1.setAdapter(adapter1);
magic1.setOnItemSelectedListener(this);

        //global 2, 3, and 4 are also positions. 
        //Is there a way to set those to disabled states?

1 个答案:

答案 0 :(得分:4)

   // Create spinner month, and disable month < today
    List<CharSequence> listMonth = new ArrayList<CharSequence>();
    for (int m = 0; m < 12; m++) {
        if (m < 9) {
            listMonth.add("0" + (m + 1));
        } else {
            listMonth.add("" + (m + 1));
        }
    }
        // Create spinner item
    adapterMonth = new ArrayAdapter<CharSequence>(this,
            R.layout.layout_spinner_item, listMonth) {
         // Disable click item < month current
        @Override
        public boolean isEnabled(int position) {
            // TODO Auto-generated method stub
            if (year <= max_year && position < max_month - 1) {
                return false;
            }
            return true;
        }
        // Change color item
        @Override
        public View getDropDownView(int position, View convertView,
                ViewGroup parent) {
            // TODO Auto-generated method stub
            View mView = super.getDropDownView(position, convertView, parent);
            TextView mTextView = (TextView) mView;
            if (year <= max_year && position < max_month - 1) {
                mTextView.setTextColor(Color.GRAY);
            } else {
                mTextView.setTextColor(Color.BLACK);
            }
            return mView;
        }
    };

    adapterMonth
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spn2.setAdapter(adapterMonth);