【发布时间】:2012-05-26 12:44:23
【问题描述】:
我想知道如何通过类传递数据/变量?
Class.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 中有一个 HTTPPOST 脚本。然后我有一个获取位置的类。
如何获取该位置并将其发送至sendDataDetail?我应该采取什么方法?
请注意我还在学习android,
提前谢谢你!
【问题讨论】:
标签: java android parameter-passing