[英]Android - How to perform an action until a Handler doesn't complete the delay
I have an app where the user can rate a post with a like/dislike. 我有一个应用程序,用户可以在其中对喜欢/不喜欢的帖子评分。 After that I show a view with the autor of the post for a second and update the content with another article. 之后,我与帖子的指导者展示了一下视图,并用另一篇文章更新了内容。
The code that I am using right now for this delay is: 我现在为此延迟使用的代码是:
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
nextFragment();
}
}, 1000);
I would like to provide a share functionality after the user rate the article, that will appear just for this second. 我想在用户对文章进行评分之后提供共享功能,此功能将仅在第二秒出现。 But I don't have any ideas of how to do it. 但是我对如何做到没有任何想法。 How can I show this view with the author for a second, and in case of the user click the share button, I perform the share action and comeback to the next article after that? 如何与作者保持一秒钟的距离,如果用户单击共享按钮,我将执行共享操作并在此之后返回下一篇文章?
Thanks! 谢谢!
Well why don't you just do your action before starting the handler, and cancel that action when the handler completes? 那么,为什么不只是在启动处理程序之前执行操作 ,而在处理程序完成时取消该操作呢? Example: 例:
final ProgressDialog dialog = new ProgressDialog(this);
dialog.setTitle("Something something");
dialog.show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
dialog.dismiss();
nextFragment();
}
}, 1000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.