title: Checking network status on button click
body: <p>In my android app I have a button that when clicked, opens another class that makes a network call.</p>
  
  <p>I am trying to check for a data connection when the button is clicked and if there isn't a connection I want to display a toast message.</p>
  
  <p>Here is my onclick method as it stands:-</p>
  
  <pre><code>public void GoToZone(View v)
  {
  
  
  
      if (android.os.Build.VERSION.SDK_INT &gt; 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
            Intent myIntent = new Intent(MainActivity.this, CustomizedListViewStudentZone.class);
            startActivityForResult(myIntent, 0);
          } 
  
  
      else {            
          Context context = getApplicationContext();
          CharSequence text = "There seems to be a connection issue";
          int duration = Toast.LENGTH_LONG;
          Toast toast = Toast.makeText(context, text, duration);
          toast.show();
      }
  
  
  
   }
  </code></pre>
  
  <p>How would I be able to check for a connection when the button is pressed and if there is a connection then proceed with the above and if there isn't then display a message saying "No Connection"</p>
  
  <p>I am really struggling with implementing the check.</p>
  
  <p>Thanks</p>