public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Toast.makeText(this, String.valueOf(progress), Toast.LENGTH_SHORT).show();
changeColor(viewOne, progress);
changeColor(viewTwo, progress);
changeColor(viewThree, progress);
changeColor(viewFour, progress);
changeColor(viewFive, progress);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
I am trying to update the value of the seekbar and display it in a toast. however, the toast updates the value extremely slowly. I would not like to use a textbox. Is there a way to accomplish this?
答案 0 :(得分:1)
Using popup window.You can customize the view of popup window, like a textview to show the progress. In method onStartTrackingTouch, show the popup window. In method onStopTrackingTouch, dismiss the popup window. In method onProgressChanged, change the progress. Sample code:
package com.example.test;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.PopupWindow;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.SeekBar.OnSeekBarChangeListener;
public class MainActivity extends Activity implements OnSeekBarChangeListener {
private SeekBar seek;
private PopupWindow window;
private TextView textview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seek = (SeekBar) findViewById(R.id.seek);
seek.setOnSeekBarChangeListener(this);
window = new PopupWindow(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
textview = new TextView(this);
textview.setTextSize(16);
textview.setBackgroundColor(Color.BLACK);
textview.setTextColor(Color.WHITE);
window.setContentView(textview);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
textview.setText("progress : " + progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
window.showAsDropDown(seek);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
window.dismiss();
}
}
Hope it helps.
答案 1 :(得分:0)
在班级宣布祝酒词
Toast mToast;
在constructor
或onCreate
protected void onCreate(Bundle savedInstanceState) {
...
mToast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
}
然后当你需要展示吐司时
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
mToast.setText("progress : " + progress);
mToast.show();
}
现在你的吐司更新将是即时的。
答案 2 :(得分:0)
根据上面的第二个答案,在班级宣布敬酒。
我删除了.scss
已更改为context
MainActivity.this