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