Android TabHost 中的 Activity 重新加载问题

烦恼的大胖 发布于 2012/04/08 22:44
阅读 6K+
收藏 3
用 TabHost 布的一个各个分类新闻的 activity ,做了一个刷新按钮,求教怎么可以让这个 activity 在tabhost 中刷新??因为使用startActivity 会跳出 TabHost 布局,想了半天了,还是没出解决办法...
加载中
0
echocao
echocao

实例化一个Handler对象,并重写handleMessage方法调用invalidate()实现界面刷新;而在线程中通过sendMessage发送界面更新消息。

 

       // onCreate()中开启线程

       new Thread(new GameThread()).start();

 

       // 实例化一个handler

       Handler myHandler   = new Handler()

       {

              //接收到消息后处理

              public void handleMessage(Message msg)

              {

                     switch (msg.what)

                     {

                     case Activity01.REFRESH:

                            mGameView.invalidate();        //刷新界面

                            break;

                     }

                     super.handleMessage(msg);

              }                  

       };

 

       class GameThread implements Runnable

       {

              public void run()

              {

                     while (!Thread.currentThread().isInterrupted())

                     {

                            Message message = new Message();

                            message.what = Activity01.REFRESH;

                            //发送消息

                            Activity01.this.myHandler.sendMessage(message);

                            try

                            {

                                   Thread.sleep(100);

                            }

                            catch (InterruptedException e)

                            {

                                   Thread.currentThread().interrupt();

                            }

                     }

              }

       }

0
yinjq
yinjq
activity的布局是ListView?,是的话,更新adapter,在主线程调用listview.notifyDataSetChanged()
烦恼的大胖
烦恼的大胖
我试过线程刷新,如果在GPRS情况下,前一次刷新结果没出来,然后立刻再刷新,一直这样,结果会不停的重复,所以我想试试整个ACTIVITY刷新
返回顶部
顶部