速度警告アプリを作成していますが、作成中のある時点で立ち往生しています。速度は正しく表示されていますが、アラートが必要な設定速度が機能していません。コードを間違った場所に配置したと思います。私のコードは次のとおりです。
if( insetSpeed > intspeed);
{
Toast.makeText(speedalert.this, "Over Speed!!", Toast.LENGTH_SHORT).show();
}
すべての変数が同じ型 int に変換されました。
上記のコードの配置だけが必要です。
どうもありがとう:D
編集
public void updateSpeed(Location location)
{
float gpsSpeed = 0;
if( location!=null )
{
gpsSpeed = ((location.getSpeed()*3600)/1000);
}
intspeed = (int)gpsSpeed;
TextView intSpeedTV = (TextView) findViewById(R.id.intSpeedTV);
intSpeedTV.setText(String.valueOf(strCurrentSpeed));
TextView SpeedTextView = (TextView) this.findViewById(R.id.SpeedTextView);
SpeedTextView.setText(String.valueOf(intspeed))
}
public void onLocationChanged(Location location)
{
if (location != null)
{
Location myLocation = new Location(location);
this.updateSpeed(myLocation);
}
}
public void speedAlert(Location location)
{
if( intspeed >= 2) ;
{
Toast.makeText(SpeedAlert.this, "Over Speed!!", Toast.LENGTH_SHORT).show();
}
}
編集 2
コードを書き直しました:
public class SpeedAlert extends Activity
{
NumberPicker np;
int setSpeed;
String strsetSpeed;
int intspeed;
int intsetSpeed;
LocationListener LocLis;
LocationManager LocMan;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setContentView(R.layout.speedalertmain);
LocMan = (LocationManager) getSystemService (Context.LOCATION_SERVICE);
LocLis = new GetSpeeed();
LocMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 0, LocLis);
np = (NumberPicker) findViewById(R.id.numberPicker1);
final TextView setSpeedTV = (TextView) findViewById(R.id.setSpeedTV);
np.setMinValue(0);
np.setMaxValue(160);
np.setWrapSelectorWheel(true);
np.setOnValueChangedListener(new OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
// TODO Auto-generated method stub
String New = "";
setSpeedTV.setText(New.concat(String.valueOf(newVal)));
newVal = setSpeed;
intsetSpeed = Integer.valueOf(setSpeed);
}
});
}
private class GetSpeeed implements LocationListener
{
public void onLocationChanged(Location location) {
if(location!=null) {
float gpsSpeed = 0;
if(location.hasSpeed()){
gpsSpeed = ((location.getSpeed()*3600)/1000);
intspeed = (int)gpsSpeed;
TextView SpeedTextView = (TextView) findViewById(R.id.SpeedTextView);
SpeedTextView.setText(String.valueOf(intspeed));
TextView intSpeedTV = (TextView) findViewById(R.id.intSpeedTV);
intSpeedTV.setText(String.valueOf(intspeed));
if( intspeed >= intsetSpeed) ;
{
Toast.makeText(SpeedAlert.this, "Over Speed!!", Toast.LENGTH_SHORT).show();
}
}
}
}
}
}