0

我使用 seekBar 来传递用户增加/减少的值...我把 barValue=50 的初始值。当用户拖动搜索栏小于当前值时.. a,b 减少 0.00001。

我面临的问题。它只做一次 IF 条件。seekBar 更新后.. a 和 b 没有变化。

  public static double a,b;
     public static int barValue;


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            // Define the criteria how to select the locatioin provider -> use
            // default
            Criteria criteria = new Criteria();
            provider = locationManager.getBestProvider(criteria, false);
            Location location = locationManager.getLastKnownLocation(provider);

            a= location.getLatitude(); 
            b= location.getLongitude(); 

             bar = (SeekBar)findViewById(R.id.seekBar1); // make seekbar object
             bar.setOnSeekBarChangeListener(this); // set seekbar listener.

             barValue = 50;
             bar.setProgress(barValue);


    }


public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        // TODO Auto-generated method stub
        if (progress > barValue)
        {
            a += seekBar.getProgress()/10000; 
            b += seekBar.getProgress()/10000;

            getSensorManager().enableMockLocation(a, b);
        }
        else if(progress < barValue)
        {
            a -= seekBar.getProgress()/10000;
            b -= seekBar.getProgress()/10000;

            getSensorManager().enableMockLocation(a, b);
        }

    }


    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        // TODO Auto-generated method stub

    }


    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        // TODO Auto-generated method stub
        seekBar.setSecondaryProgress(seekBar.getProgress());
        barValue = seekBar.getProgress();
    }
4

0 回答 0