如何在考虑计时器延迟的同时重复 Toast 一定次数,而不仅仅是让它像现在这样循环?
public class MainActivity extends Activity {
Button btn;
EditText edit;
TextView view;
Timer myTimer = new Timer();
MyTimerTask myTimerTask= new MyTimerTask();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn =(Button)findViewById(R.id.bu);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edit=(EditText)findViewById(R.id.ed1);
view=(TextView)findViewById(R.id.te);
int aa = Integer.valueOf(edit.getText().toString());
view.setText(edit.getText().toString());
myTimer.scheduleAtFixedRate(myTimerTask, aa, aa);
}
});
}
private class MyTimerTask extends TimerTask {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run()
//code to do
Toast.makeText(getBaseContext(), "Toast test", Toast.LENGTH_SHORT).show(); //how to repeat this toast for certain counts not just looping like now
}
});
}
}