简体   繁体   中英

Enable/Disable RelativeLayout view(s) on Spinner select

I have three Relativelayout views set up in my XML one after eachother, in my onCreate method I have initialised all three views and setEnabled() to false. Then I have set up a Spinner and I want to enable each view when each respective button is clicked. Is there a way to do this? So far I have (on my Spinner):

        public void onItemSelected(AdapterView<?> parent, View arg1,
                int position, long arg3) {
            // TODO Auto-generated method stub
            if (parent.getItemAtPosition(position).equals("Quantity")) {
                calSelectInt = 1;
                calSeek.setEnabled(true);
                calWeight.setEnabled(false);
                calFlour.setEnabled(false);
            } else if (parent.getItemAtPosition(position).equals("Dough Weight")) {
                calSelectInt = 2;
                calSeek.setEnabled(false);
                calWeight.setEnabled(true);
                calFlour.setEnabled(false);
            } else if (parent.getItemAtPosition(position).equals("Flour Weight")) {
                calSelectInt = 3;
                calSeek.setEnabled(false);
                calWeight.setEnabled(false);
                calFlour.setEnabled(true);
            }
        }

The cal___ represents each view. The calSelectInt is an attempt to set an Integer for each and call in another method when each Integer is read.

As a result when run, all three views are viewed, any ideas? Why isn't setEnabled working? Or is my code poorly thought out. Thanks

Turns out I had to setVisibility(View.GONE) and (View.VISIBLE) instead of setEnabled(boolean). Strange, that method didn't seem to work for me in the past with other things but hey ho.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM