我有一个Android应用程序,使用谷歌地图,如果GPS获取连接到Android设备我有一个按钮和EditText,我不想显示向上。 On Create方法的代码如下。试图让一个按钮和edittext不显示为一个Android应用程序
如果isGPS为true,则按钮和标签仍然显示。当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();
}
}
您需要的时候曾经在GPS关闭它们的可见性设置为View.VISABLE。 – Pragnani 2013-04-04 01:21:30
对不起,我在我的问题有一个错字,我实际上需要让edittext和按钮消失,如果isGPS为false。 – yams 2013-04-04 15:23:54
当前状态是什么?当你运行这段代码时会发生什么? – 2013-04-04 16:34:25