我可以显示使用runOnUiThread敬酒的一个例子。 [英] Can i have an example of displaying a toast using runOnUiThread.

查看:112
本文介绍了我可以显示使用runOnUiThread敬酒的一个例子。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了很多地方,但找不到执行runOnUiThread的一个完整的工作示例。我尝试了很多,但获得了大量的错误。 我只是想显示从一个线程敬酒。

I searched many places but could not find a complete working example of implementation of "runOnUiThread". I tried a lot , but getting lots of errors . I just want to display a toast from a thread.

推荐答案

因此​​,这里是最后的满code。感谢所有谁回答。

So here is the final full code. Thanks to all who have replied.

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends Activity {


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    MainActivity.this.runOnUiThread(new Runnable() {

        public void run() {
            Toast.makeText(MainActivity.this, "This is Toast!!!", Toast.LENGTH_SHORT).show();

        }
    });
}

}

和有关XML,它是创建的默认XML文件。没有变化需要。

And About the XML, its is the default XML file created. No change needed.

这篇关于我可以显示使用runOnUiThread敬酒的一个例子。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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