我有错误:无法解析符号" postDelayed"。在:
package com.example.hubert.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
public class ClickActivity extends AppCompatActivity {
Handler handler = new Handler();
Runnable updateCurrentTime = new Runnable() {
@Override
public void run() {
money = money + 100;
handler.postDelayed(this, 1000);
}
};
handler.postDelayed(updateCurrentTime, 500);
(...)
}
这是我的一些代码:
{{1}}
我读了其他类似的问题,所有答案都很糟糕。
答案 0 :(得分:2)
您必须将语句放在方法中。
与此类似:
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_main);
handler.postDelayed(updateCurrentTime, 500);
}