计时器线程刷新Android上的片段 [英] timer thread to refresh the fragment on android

查看:111
本文介绍了计时器线程刷新Android上的片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现在Android的线程它刷新每1秒钟的片段(某些文本列表)。

I have implemented a thread in android which refresh the fragment (some text list ) for every 1 second .

它给人运行时错误,而在调用线程片段的方法。这里是我的code

its giving the runtime error while calling the fragment method at thread ,. here is my code

public class RunThreadExtended extends Activity implements Runnable
{
public void run() {

 while(true)
 {  try {
    Thread.sleep(1000);
    AndroidListFragmentActivity.strup++;
    MyListFragment1 fragmentB = (MyListFragment1)getFragmentManager().findFragmentById(R.id.fragment1);
    fragmentB.updatefrag();
} catch (InterruptedException e) {
    e.printStackTrace();
}
  }}}

如果我把从Mainactivity一切片段的方法,从工作,因为我需要刷新线程在研究背景,每5秒我有这样实现的,但它不工作..pls建议的解决方案...

If I call the fragment method from Mainactivity everything works from , since I need to refresh the thread for every 5 seconds in the backgroud I have implemented like this , but its not working ..pls suggest solution ...

推荐答案

我认为你必须做的清爽

yourActivity.runOnUiThread(new Runnable() {
public void run()   { /* here */ });

或通过处理程序,或通过后()或者在的AsyncTask onProgress()

Or via a Handler, or via a post() or in an AsyncTask's onProgress()

这篇关于计时器线程刷新Android上的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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