我使用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();
}