Android 搜索栏文本视图
Android seekbar textView
我有3个seekbar来改变背景颜色。每个搜索栏都有一个 0-255 的 textView,以 RGB 格式显示颜色代码。当我滑动其中一个搜索栏时,RGB textView 全部改变。我如何指定,只有属于搜索栏的textView,我滑动才会改变?
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) {
}
};
您正在 OnProgressChanged 方法中获取 SeekBar 对象,您可以将其 id 与您的个人 SeekBar 进行比较。试试下面的代码:
@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);
}
}
希望这会有所帮助!!
我有3个seekbar来改变背景颜色。每个搜索栏都有一个 0-255 的 textView,以 RGB 格式显示颜色代码。当我滑动其中一个搜索栏时,RGB textView 全部改变。我如何指定,只有属于搜索栏的textView,我滑动才会改变?
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) {
}
};
您正在 OnProgressChanged 方法中获取 SeekBar 对象,您可以将其 id 与您的个人 SeekBar 进行比较。试试下面的代码:
@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);
}
}
希望这会有所帮助!!