我正在测试搜索栏组件以获得感觉,所以我将它添加到我的应用程序中。目标很简单,当您拖动光标时,它会更改文本以指示进度。但是由于某种原因,当在屏幕上拖动它时,它会留下光标的图像以及以前的结果,而不是仅仅用新的文本替换文本。这是代码。我认为非常基本。
public class Progressbar extends Activity implements OnSeekBarChangeListener
{
SeekBar bar; // declare seekbar object variable
// declare text label objects
TextView textAction;
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// load the layout
setContentView(R.layout.activity_progressbar);
bar = (SeekBar)findViewById(R.id.seekBar1); // make seekbar object
bar.setOnSeekBarChangeListener(this); // set seekbar listener.
// since we are using this class as the listener the class is "this"
// make text label for action
textAction = (TextView)findViewById(R.id.textViewAction);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
// change action text label to changing
textAction.setText(textAction.getText() + "\n" +"SeekBar progress is at: "+ progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
textAction.setText("starting to track touch");
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
seekBar.setSecondaryProgress(seekBar.getProgress()); // set the shade of the previous value.
textAction.setText("ended tracking touch");
}
}