我写了一个程序,你可以给用户提供位置,然后给他看位置。获取位置我使用自定义对话框,但我不知道如何使用用户输入的位置。例如,我使用一个按钮接受值,但每次我使用此方法我都会收到错误。 这是我使用按钮并获得错误的来源:
public class main extends MapActivity {
/** Called when the activity is first created. */
EditText lat;
EditText lang;
Integer latitude;
Integer longtitude;
Button b = (Button) findViewById(R.id.button1);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView view = (MapView) findViewById(R.id.themap);
view.setBuiltInZoomControls(true);
final MapController control = view.getController();
LocationManager manager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
LocationListener listener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location location) {
latitude = Integer.valueOf(lat.getText().toString());
longtitude = Integer.valueOf(lang.getText().toString());
control.setCenter(new GeoPoint(latitude, longtitude));
}
};
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Dialog d = new Dialog(main.this);
d.setContentView(R.layout.choose);
d.setTitle("Location");
d.show();
lat = (EditText) findViewById(R.id.editText1);
lang = (EditText) findViewById(R.id.editText2);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
return super.onOptionsItemSelected(item);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
这是我的权限:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
所以这是我的问题:
为什么我得到错误以及我如何解决这个问题,我的意思是我如何使用此按钮关闭我的自定义对话框并设置位置。
logcat:
05-23 13:15:10.953: W/KeyCharacterMap(13490): No keyboard for id 131074
05-23 13:15:10.953: W/KeyCharacterMap(13490): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
05-23 13:15:21.434: W/MapActivity(13490): Recycling dispatcher android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher@40719228
05-23 13:15:21.444: V/MapActivity(13490): Recycling map object.
05-23 13:15:21.524: I/MapActivity(13490): Handling network change notification:CONNECTED
05-23 13:15:21.524: E/MapActivity(13490): Couldn't get connection factory client