2013-04-04 36 views
0

我有一個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(); 
    } 

} 
+0

您需要的時候曾經在GPS關閉它們的可見性設置爲View.VISABLE。 – Pragnani 2013-04-04 01:21:30

+0

對不起,我在我的問題有一個錯字,我實際上需要讓edittext和按鈕消失,如果isGPS爲false。 – yams 2013-04-04 15:23:54

+0

當前狀態是什麼?當你運行這段代碼時會發生什麼? – 2013-04-04 16:34:25

回答

0

您需要否定isGPS:

if(!isGPS) { 
    // This gets run ig isGPS is false 
} 
+0

如果isGPS爲真,我需要讓Button和EditText不顯示。' – yams 2013-04-04 15:02:08

+0

對不起,我在我的問題上有一個類型。 – yams 2013-04-04 15:04:32

+0

最有可能的是,您將通過運行調試器並查看isGPS的值來解決此問題。我的猜測是,你的假設是錯誤的,GPS從未啓用,所以按鈕永遠不會被隱藏。 – 2013-04-04 19:46:09

-1

你的if語句檢查是否isGPS是真實的,然後設置按鈕是無形的,如果它是。

通過它的聲音,你想設置按鈕不可見,只有當isGPS是假的。

你需要if (!isGPS)而不是(isGPS)

+0

如果isGPS爲真,我需要讓Button和EditText不顯示。' – yams 2013-04-04 15:01:26

+0

對不起,我在我的問題上有一個類型。 – yams 2013-04-04 15:03:08

+0

當isGPS爲真時,我非常想讓按鈕和edittext不出現。 – yams 2013-04-04 16:16:46

相關問題