2013-04-04 34 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

相关问题