0
我正在測試seek bar組件以獲得它的感覺,所以我將它添加到我的應用程序中。目標很簡單,當您拖動光標時,它將更改文本以指示進度。但由於某些原因,在屏幕上拖動它時,會留下光標圖像以及之前的結果,而不是僅僅用新的結果替換文本。這是代碼。非常基本的我會想。Seekbar和setText顯示舊輸出
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");
}
}
我已經這樣做了,但是設置的文本顯示在對方的頂部,而不是隻顯示新的。所以它只是看起來很亂。 – user2243369 2013-04-04 18:26:45
你的代碼很好也許xml佈局文件有問題 – Hasham 2013-04-05 05:55:16