1
我需要此线程循环缓慢,并在用户按下buttonStart后,在integerTime的持续时间内暂停。当谈到Android时,我是一个业余爱好者,并且我花了大约12个小时试图让这个工作。如果有人能帮助或纠正我的代码,我将非常感激。干杯。为什么这个线程暂停并循环?
final Button button = (Button) findViewById(R.id.buttonStart); // Making the button to launch the
button.setOnClickListener(new View.OnClickListener() { // actions below
public void onClick(View v) {
editTextTarget = (EditText)findViewById(R.id.editTextTarget); // After user presses 'Start', it will
stringTarget = editTextTarget.getText().toString(); // convert the input 'Target' into a string
editTextPayload = (EditText)findViewById(R.id.editTextPayload); // After user presses 'Start', it will
stringPayload = editTextPayload.getText().toString(); // convert the input 'Payload' into a string and
integerPayload = Integer.parseInt(stringPayload); // then convert the string into an integer
editTextTime =(EditText)findViewById(R.id.editTextTime); // After user presses 'Start', it will
stringTime = editTextTime.getText().toString(); // convert the input 'Time' into a string and
integerTime = Integer.parseInt(stringTime); // then convert the string into an integer
Thread threadBegin = new Thread()
{
public void run(){
while (DOSrunning.get()) {
try {
Thread.sleep(integerTime);
} catch (ClientProtocolException e) {
} catch (IOException e) {
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
;};
threadBegin.start();
整数时间以毫秒为单位? – 2012-03-23 22:27:58
您的要求不明确... – waqaslam 2012-03-23 22:30:40