我有一个使用 Google 地图的 Android 应用程序,如果 GPS 连接到 Android 设备,我有一个我不想显示的 Button 和 EditText。On Create 方法的代码如下。
如果 isGPS 为真,按钮和标签仍会显示。当isGPS为真时,我真的希望按钮和edittext不出现。任何帮助,将不胜感激。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
final boolean isGPS = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
setContentView(R.layout.activity_map_view_wogps);
showCurrentLocationOnMap();
// Getting reference to btn_find of the layout activity_main
Button btn_find = (Button) findViewById(R.id.btn_find);
final EditText etLocation = (EditText) findViewById(R.id.et_location);
if (isGPS){
btn_find.setVisibility(View.GONE);
etLocation.setVisibility(View.GONE);
}
// Defining button click event listener for the find button
OnClickListener findClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
// Getting user input location
String location = etLocation.getText().toString();
if(location!=null && !location.equals("")){
AsyncTask<String, Void, List<Address>> execute = new GeocoderTask().execute(location);
}
}
};
// Setting button click event listener for the find button
btn_find.setOnClickListener(findClickListener);
try {
showSheltersAndFuelStops();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}