我想知道如何通过类传递数据/变量?
类.java
public class AddItem extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
mlocListener = new CurrentLocation();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
}
}
public void sendDataDetail(View v){
// This is where my HTTPPOST goes, need the location here
}
public class CurrentLocation implements LocationListener {
@Override
public void onLocationChanged(Location loc) {
// TODO Auto-generated method stub
loc.getLatitude();
loc.getLongitude();
String Text = "My Current Location is: " + "Lat = " + loc.getLatitude() + "Long = " + loc.getLongitude();
Toast.makeText(getApplicationContext(),Text,Toast.LENGTH_SHORT).show();
}
}
所以基本上,我在 onCreate 中有 CurrentLocation(),然后在sendDataDetail
. 然后我有一个类可以获取位置。
如何获取该位置并将其发送到sendDataDetail
?我应该采取什么方法?
请注意,我还在学习android,
先感谢您!