Search code examples
androidseekbar

how to bind button with text with Seekbar thumb at run time


Hi I want to bind button with text with seekbar thumb. so that if I move the seekbar thumb the button with dynamic text move along with that.

enter image description here Please suggest how to do that.

Thanks in advance.


Solution

  • Try Something like below:

     protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_seekbar_test);
    
        seek = (SeekBar) findViewById(R.id.seekBar1);
        text = (TextView) findViewById(R.id.textView1);
    
        seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {       
            @Override       
            public void onStopTrackingTouch(SeekBar seekBar) {            
            }       
            @Override       
            public void onStartTrackingTouch(SeekBar seekBar) {     
            }       
            @Override       
            public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
                setTxt(progress);
            }
        });
    }
    
    private void setTxt(int prg)
    {
        text.setX((float)prg);
    }