android实现自动点击按钮
怎么实现每隔1s钟按钮就自动点击呢?path_button.setOnClickListener(newOnClickListener(){@Overridepublic...
怎么实现每隔1s钟按钮就自动点击呢?
path_button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
init();
}
}); 展开
path_button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
init();
}
}); 展开
1个回答
2014-04-03
展开全部
Timer timer = new Timer();
Handler handler = new Handler(){
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
path_button.performClick();
break;
}
super.handleMessage(msg);
}
};
TimerTask task = new TimerTask(){
public void run() {
Message message = new Message();
message.what = 1;
handler.sendMessage(message);
}
};
timer.schedule(task,0, 1*1000);
追问
path_button=(Button)findViewById(R.id.button2);
path_button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
timer.schedule(task,0, 1*1000);
init();
}
});
程序挂了,哪错了?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询