SLaks 2013-09-09 09:44 采纳率: 0%
浏览 2068
已采纳

Android 中 TextView 的 lag

下面是我的代码,TextView 被分成两组,要求其中一组要比另一组好。

   public void onLocationChanged(Location location) 
    {
        // TODO Auto-generated method stub
        if(predictionFlag)
        {
            longitude = location.getLongitude();
            latitude = location.getLatitude();
            predictionFlag = false;
        }
        int x = 0;
        do
        {
            if(x != 0)
            {
                try 
                {
                    Thread.sleep(100);
                } catch (InterruptedException e) 
                  {
                    e.printStackTrace();
                  }
            }
            Location predicationPoint = DOTGpsAppUtils.predictionAlgorithm(latitude, longitude, 1, 100);
            double predictionLongitude = (longitude + predicationPoint.getLongitude())/2;
            double predictionLatitude = (latitude + predicationPoint.getLatitude())/2;
            TextView textView = (TextView) findViewById(R.id.oneHundredMillisecondLatitude);
            textView.setText(Double.valueOf(predictionLatitude).toString());
            textView = (TextView) findViewById(R.id.oneSecondCalculatedPointLongitude);
            textView.setText(Double.valueOf(predictionLongitude).toString());
            if(x == 9)
            {
                longitude = predictionLongitude;
                latitude = predictionLatitude;
            }
            System.out.println(x);
            ++x;
        }while(x < 10);

        TextView textView = (TextView) findViewById(R.id.startingPointLongitude);
        textView.setText(Double.valueOf(location.getLongitude()).toString());
        textView = (TextView) findViewById(R.id.startingPointLatitude);
        textView.setText(Double.valueOf(location.getLatitude()).toString());
        textView =  (TextView) findViewById(R.id.oneSecondCalculatedPointLongitude);
        textView.setText(Double.valueOf(longitude).toString());
        textView = (TextView) findViewById(R.id.oneSecondCalculatedLatitude);
        textView.setText(Double.valueOf(latitude).toString());
        ++y;
        System.out.println("Thread Count:" + y);
    }

在 android 屏幕上为什么不能快速更新 R.id.oneHundredmilliesecand 和其它的 textviews?

  • 写回答

1条回答

  • Jobernowl 2013-09-10 04:26
    关注
    public void onLocationChanged(final Location location) 
        {
            // TODO Auto-generated method stub
            runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if(predictionFlag)
            {
                longitude = location.getLongitude();
                latitude = location.getLatitude();
                predictionFlag = false;
            }
            int x = 0;
            do
            {
                if(x != 0)
                {
                    try 
                    {
                        Thread.sleep(100);
                    } catch (InterruptedException e) 
                      {
                        e.printStackTrace();
                      }
                }
                Location predicationPoint = DOTGpsAppUtils.predictionAlgorithm(latitude, longitude, 1, 100);
                double predictionLongitude = (longitude + predicationPoint.getLongitude())/2;
                double predictionLatitude = (latitude + predicationPoint.getLatitude())/2;
                TextView textView = (TextView) findViewById(R.id.oneHundredMillisecondLatitude);
                textView.setText(Double.valueOf(predictionLatitude).toString());
                textView = (TextView) findViewById(R.id.oneSecondCalculatedPointLongitude);
                textView.setText(Double.valueOf(predictionLongitude).toString());
                if(x == 9)
                {
                    longitude = predictionLongitude;
                    latitude = predictionLatitude;
                }
                System.out.println(x);
                ++x;
            }while(x < 10);
    
            TextView textView = (TextView) findViewById(R.id.startingPointLongitude);
            textView.setText(Double.valueOf(location.getLongitude()).toString());
            textView = (TextView) findViewById(R.id.startingPointLatitude);
            textView.setText(Double.valueOf(location.getLatitude()).toString());
            textView =  (TextView) findViewById(R.id.oneSecondCalculatedPointLongitude);
            textView.setText(Double.valueOf(longitude).toString());
            textView = (TextView) findViewById(R.id.oneSecondCalculatedLatitude);
            textView.setText(Double.valueOf(latitude).toString());
            ++y;
            System.out.println("Thread Count:" + y);
                    }
                });
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 github符合条件20分钟秒到账,github空投 提供github账号可兑换💰感兴趣的可以找我交流一下
  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?