从一个单独的线程级的Andr​​oid敬酒消息 [英] Android toast message from a separate thread class

查看:112
本文介绍了从一个单独的线程级的Andr​​oid敬酒消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑如何使用吐司打印出的消息。 我需要用它来打印出来自线程的while循环的消息。 我的线程这使得显卡在不同的班比我的活动。 我的意思是,它们不会在同一文件中实现。 有没有办法做到这一点?

I am confused about how to use Toast to print out messages. I need to use it to print out messages that come from the thread's while loop. My thread which renders graphics are on a different class than my activity. I mean, they are not implemented in the same file. Is there a way to do this?

推荐答案

您可以使用<一个href="http://developer.android.com/reference/android/app/Activity.html#runOnUiThread%28java.lang.Runnable%29"相对=nofollow> runOnUiThread :

myActivity.runOnUiThread(new Runnable() {

 public void run() {
    Toast.makeText(context, text, duration).show();
 }

});

这篇关于从一个单独的线程级的Andr​​oid敬酒消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆