J
Jajobe
Erfahrenes Mitglied
- 14
Ich versuche gerade einen Androidtacho zu programmieren.
Im Netz bin ich darauf gestoßen, dass man mit location.getSpeed nur m/s bekommt. Deswegen habe ich das Ergebnis mal 3.6 genommen. Stimmt das?
Quellcode:
Außerdem habe ich noch ne Frage, nämlich wie macht man als Hintergrund einen Tacho?
Also ich bekomme im Moment Geschwindigkeiten in einer Textview, aber möchte, dass sich ein Zeiger über einen Tacho bewegt.
Gibt es dazu irgendwo ne Anleitung?
Im Netz bin ich darauf gestoßen, dass man mit location.getSpeed nur m/s bekommt. Deswegen habe ich das Ergebnis mal 3.6 genommen. Stimmt das?
Quellcode:
Code:
package com.bjcreative.speedometer;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity implements LocationListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LocationManager lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
this.onLocationChanged(null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onLocationChanged(Location location) {
TextView txt = (TextView) this.findViewById(R.id.textView1);
if( location==null )
{
txt.setText("-.- km/h");
}
else
{
float nCurrentSpeed = location.getSpeed();
txt.setText(nCurrentSpeed*3.6 + "km/h");
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
Außerdem habe ich noch ne Frage, nämlich wie macht man als Hintergrund einen Tacho?
Also ich bekomme im Moment Geschwindigkeiten in einer Textview, aber möchte, dass sich ein Zeiger über einen Tacho bewegt.
Gibt es dazu irgendwo ne Anleitung?
Zuletzt bearbeitet: