改变图像中使用ImageView的主题 [英] Changing image in imageview using Threads
本文介绍了改变图像中使用ImageView的主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到错误与此code。为什么忽忽 123123123
发定时器=新的Thread()
{
公共无效的run()
{
尝试
{
睡眠(1500);
splash.setImgeResource(R.drawable.dilclogo);
睡眠(1500);
}
赶上(InterruptedException的E)
{
e.printStackTrace();
}
最后
{
意向意图=新的意图(MainActivity.this,MenuScreen.class);
startActivity(意向);
}
}
};
timer.start();
解决方案
这是因为你不能直接从任何其他线程访问UI /主线程。您可以使用下面的方法,虽然访问您的UI线程:
- 使用
的AsyncTask
- 使用<一个href="http://developer.android.com/reference/android/app/Activity.html#runOnUiThread%28java.lang.Runnable%29"相对=nofollow>
runOnUiThread()
您还可以阅读 这 一>在线程文章的android 的帮助你理解这个概念比较好。
I'm getting error with this code. Why huhu 123123123
Thread timer = new Thread()
{
public void run()
{
try
{
sleep(1500);
splash.setImgeResource(R.drawable.dilclogo);
sleep(1500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
finally
{
Intent intent = new Intent(MainActivity.this, MenuScreen.class);
startActivity(intent);
}
}
};
timer.start();
解决方案
This is because you can NOT access your UI/Main thread directly from any other thread. You can use below methods to access your UI thread though:
- Using
AsyncTask
- Using
runOnUiThread()
You can also read this article on threading in android to help you understand this concept better.
这篇关于改变图像中使用ImageView的主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文