What do i do to be able to use a handler to update my TextView every 2 secs because right now it comes up with 'cannot resolve symbol"Handler"'
int noStart = 20;
int minus = 5;
public void number(View view) {
final TextView tx = (TextView) findViewById(R.id.number);
if(noStart<0){
new Handler().postDelayed(new Runnable() {
public void run() {
noStart -= minus;
tx.setText(String.valueOf(noStart));
}
}, 2000);
}
}
检查您的活动导入并将此行添加到类中:
import android.os.*
In my case, i refer to a constant of class Handler in outer calss, see as below:
import static *.MyHandler.MSG_WHAT_PING_NETWORK;
public class OuterClass {
// use MSG_WHAT_PING_NETWORK...
// ...
}
class MyHandler extends Handler {
public static final int MSG_WHAT_PING_NETWORK = 99;
// ...
}
remove the import in outer class can solve the problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.