我有一个活动ShowList
,我有一些edittext
领域和buttons
. 我有一个button
“ get location
”,它得到了current location
with GPS
。
(ShowList activity
效果很好,我可以得到location
):
public class ShowList extends Activity implements OnClickListener{
GPSTracker gps; //i use GPSTracker to get the location (it is not an activity)
.........
case R.id.getlocation:
// create class object
gps = new GPSTracker(ShowList.this);
// check if GPS enabled
if(gps.canGetLocation()){
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
}else{
...
}
我有一个自定义适配器:
public class myAdapter extends BaseAdapter{
ShowList locationclass=new ShowList();
.....
TextView Location = (TextView) convertView.findViewById(R.id.text_location);
String lat=Double.toString(locationclass.gps.getLatitude());
String lo=Double.toString(locationclass.gps.getLongitude());
String coordinates="Lat: " + lat + " Long: " + lo;
Location.setText(coordinates);
我收到了nullpointer
" String lat..."。
那么,我怎样才能传递location
fromShowList activity
到adapter
?