这几天在开发过程中涉及一个动态刷新UI的程序,刷新过程通过开辟个新的线程来执行,但操作过程中一直没测试到结果通过对程序的跟踪调试后发现主界面一直没刷新,折腾一番后,发现需要通过Handler组件通知主线程更新。这里引用一个简单的例子说明下,如果有什么问题可以直接留言给我。

        Handler homeAcHandler = new Handler(){
                public void handleMessage(Message msg)
                {
                        MyImageView myImageView = null;
                        if(msg.what == 0)
                        {
                                Log.d(LOG_TAG, "has recive msg");
                                synchronized (locationinfo.LOC_OBJECT) {
                                    for (int i = 0; i <arraylist.size(); i++) {                     
                                            int location_x,location_y;
                                            location_x=(int)locationinfo.neighbourCollectionFinal.get(i).x;
                                            location_y=(int)locationinfo.neighbourCollectionFinal.get(i).y;
                                            myImageView=new MyImageView(XX.this,150,50,0.2f,0.5f,0.1f,0.6f);                                            
                                    myImageView.setImageResource(R.drawable.stars_woman);
                                    mMyImageViewList.add(myImageView);
                                }
                                }
                                for(int i=0;i<mMyImageViewList.size();i++)
                             {
                                     mStarsRealtiveLayout.addView(mMyImageViewList.get(i));//添加到界面
                             }
                                mMyImageViewList.clear();//清理
                        }
                }
        }

文章出处:EyeAndroid

相关文章:

  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-09
  • 2021-11-29
  • 2022-01-19
  • 2021-05-15
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
相关资源
相似解决方案