[英]Android - How to refresh an activity
我想知道如何刷新活动。 不喜欢重启它,而是刷新它。 发生的事情是我将其打开,因此按钮点亮,单击它后等待5秒钟,然后重置按钮,另一个按钮点亮,唯一的问题是其他按钮没有点亮,因为它一直卡在相同的按钮。 我不知道这是否是代码问题,或者我没有调用刷新等。任何帮助都很好! 谢谢。
if(selected == target) {
Toast.makeText(getApplicationContext(), "Good job!", Toast.LENGTH_SHORT).show();
view.getBackground().setColorFilter(Color.GREEN, PorterDuff.Mode.MULTIPLY);
} else {
Toast.makeText(getApplicationContext(), "Wrong!", Toast.LENGTH_SHORT).show();
view.getBackground().setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY);
}
h.postDelayed(task, millisDelay);
那么我的任务是这样的:
private Runnable task = new Runnable() {
public void run() {
ResetButtons();
int rnd = new Random().nextInt(buttons.length);
i = rnd;
buttons[i].getBackground().setColorFilter(Color.YELLOW, PorterDuff.Mode.MULTIPLY);
}
};
尝试这个:
public void onClick (View v){
Intent intent = getIntent();
finish();
startActivity(intent);
}
(要么)
这是我在更改首选项更改的返回值后重新加载活动的操作。
@Override
protected void onResume() {
super.onResume();
this.onCreate(null);
}
这实质上导致活动重绘自身。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.