简体   繁体   中英

using 2 seekbars in the same activity

I have 2 seekbars A and B and i have 2 textviews C and D. A edits the value of C when moved and B edits the value of D when moved. My code works fine. However I want it so that when the user is using A then seekbar B becomes disabled and likewise when seekbar B is being used by the user A becomes disabled. The way the seekbars become undisabled is when a user clicks on it to use it again. So if i were using seekbar A then B would be disabled then if i touched seekbar B it would be enabled and then A would be disabled. Or even if it ment changing the seekbars colour which is blue at the moment to a light grey colour to give the illusion that it is disabled would be another way perhaps. Neway i tried this. for seekbar A

        @Override
        public void onStartTrackingTouch(SeekBar seekbar) {
            // TODO Auto-generated method stub

             seekbarB.setEnabled(false);
             seekbarA.setEnabled(true);
        }
        @Override
        public void onStopTrackingTouch(SeekBar seekbar) {
            // TODO Auto-generated method stub
             seekbarB.setEnabled(true);
             seekbarA.setEnabled(true);
        }

and for seekbar B

@Override
        public void onStartTrackingTouch(SeekBar seekbar) {
            // TODO Auto-generated method stub
             seekbarB.setEnabled(true);
             //seekbarA.setEnabled(false);

        }
        @Override
        public void onStopTrackingTouch(SeekBar seekbar) {
            // TODO Auto-generated method stub
             seekbarB.setEnabled(true);
             seekbarA.setEnabled(true);
        }

but however this kind of worked but then when the user stopped using either of the seekbars the one that had been disabled became enabled again which I didnt want unless the user touched it. Now i know what your thinking dont set the seekbars to enabled in the onstoptrackingtouch. Well i tried that and the seekbar that was disabled would never become enabled even if you touched it i even implemented an ontouchlistener for each seekbar to see if it would become active but it didnt. so i have three ways of you guys helping me. 1. Is there a way to edit my method above to get it working the way i want? 2. Where can i put my enable seekbar method so that the seekbar only becomes active when the user touches it thus achieving what i stated above? 3. Is there a way to change a custom seekbars colours in java to achieve what i want

You could try the following: put the SeekBar in a Layout that wrap the SeekBar and put a OnTouchListener on the Layout , then re-enable the SeekBar when the user touches the Layout .

The color of the SeekBar cannot be easily changed afaik (you need to create colored resources, see this site to generate such resouces).

If you want to communicate to the user that he can only use one SeekBar at a time, I would, instead of using

seekbar.setEnabled(false)

just reduce the alpha of the SeekBar , making it 'pale'. Use seekBar.setAlpha() or, if you want to target API levels < 11, use this library 's ViewHelper class.

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