0
我試圖將一個類中的GPS座標值存儲到另一個類中。基本上我有一個按鈕,目前我用意圖來改變顯示座標的佈局。我想在按鈕上單擊存儲座標,但我不確定您是否應該使用intent,run()或其他任何東西。Android:調用一個單獨的類來返回值
我想從拉代碼是這樣的:
public class gps extends Activity implements LocationListener {
//
// body
//
private void printLocation(Location location) {
output2.append("Lat:"+location.getLatitude()+"\nLong: "+location.getLongitude());
latitude = Math.round(location.getLatitude());
longitude = Math.round(location.getLongitude());
Toast.makeText(getBaseContext(), "Lat: " + latitude + "| Long: " + longitude, Toast.LENGTH_LONG).show();
}
其中的值店「緯度」和「經度」
我用這個屏幕之間切換:
Button gpsbtn = (Button) findViewById(R.id.gps); //temp use of gps button
gpsbtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
//Toast.makeText(getApplicationContext(), "Please wait...", Toast.LENGTH_LONG).show();
Intent gpsIntent = new Intent(view.getContext(), gps.class);
startActivityForResult(gpsIntent, 0);
}
});
我只想存儲一個數值。 謝謝!
我用它來改變當前屏幕: Intent gpsIntent = new Intent(view.getContext(),gps.class); startActivityForResult(gpsIntent,0); – Nick 2011-06-06 18:26:56
所以你想讓這個gps類將這兩個值返回給調用gps的活動? 將值打包到上述代碼末尾的intent中,直接使用setExtra()或使用Bundle對象。 'code'Test – Pedantic 2011-06-06 20:15:05
我的意思是putExtra() – Pedantic 2011-06-06 20:39:33