程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> textview-Android 中 TextView 的 lag

textview-Android 中 TextView 的 lag

編輯:編程綜合問答
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?

最佳回答:


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);
                }
            });
    }
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved