我有一個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