I have 3 seekbar to change the background color. Each seekbar har a textView from 0-255 to show the colorcode in RGB. When I slide one of the seekbar, the RGB textView change on all. How can I specify, so only the textView that belong to the seekbar, that I slide will change?
private SeekBar.OnSeekBarChangeListener seekBarChangeListener
= new SeekBar.OnSeekBarChangeListener()
{
TextView seekBar1Progress;
TextView seekBar2Progress;
TextView seekBar3Progress;
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
updateBackground();
seekBar1Progress = (TextView) findViewById(R.id.viewSlider1);
seekBar1Progress.setText(" " + progress);
seekBar2Progress = (TextView) findViewById(R.id.viewSlider2);
seekBar2Progress.setText(" " + progress);
seekBar3Progress = (TextView) findViewById(R.id.viewSlider3);
seekBar3Progress.setText(" " + progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
};
You are getting SeekBar object in OnProgressChanged method, you can compare its id to your individual SeekBar. Try below code:
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
if(seekBar.getId()==R.id.seekBar1){
seekBar1Progress = (TextView) findViewById(R.id.viewSlider1);
seekBar1Progress.setText(" " + progress);
}else if(seekBar.getId()==R.id.seekBar2){
seekBar2Progress = (TextView) findViewById(R.id.viewSlider2);
seekBar2Progress.setText(" " + progress);
}else{
seekBar3Progress = (TextView) findViewById(R.id.viewSlider3);
seekBar3Progress.setText(" " + progress);
}
}
Hope this will help!!
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.