title: Button not responding to OnClickListener
body: <p>I have a <code>activity</code> that loads data from server. If the error occurs I show a <code>Button</code> to reload/retry for loading data. But the <code>onClickListener</code> does not respond when I click the button. Can someone please help me with this?</p>
  
  <blockquote>
    <p>This is my activity</p>
  </blockquote>
  
  <pre><code>public class MyContactsActivity extends AppCompatActivity implements View.OnClickListener {
  
      private RecyclerView recyclerView;
      private ContactsAdapter adapter;
      private NetworkChecker networkChecker;
      private SessionManager sessionManager;
      private AppConfig appConfig;
      private RelativeLayout loading, retry;
      private Button tryAgain;
      AlertHelper alertHelper;
      final ArrayList&lt;Contact&gt; contactArrayList = new ArrayList&lt;&gt;();
      String url;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_my_contacts);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          loading = (RelativeLayout) findViewById(R.id.loadingPanel);
          retry = (RelativeLayout) findViewById(R.id.retry);
          tryAgain = (Button) findViewById(R.id.tryAgainButton);
  
          alertHelper = new AlertHelper(this);
          networkChecker = new NetworkChecker(this);
          sessionManager = new SessionManager(this);
          appConfig = new AppConfig();
  
          String phone = sessionManager.getLoggedInUserPhone();
          url = appConfig.getApiUrlForSpecificContacts(phone);
  
          tryAgain.setOnClickListener(this);
  
          recyclerView = (RecyclerView) findViewById(R.id.contactsView);
          adapter = new ContactsAdapter(getApplicationContext());
          recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
  
          sendJsonRequest(url);
          recyclerView.setAdapter(adapter);
  
          recyclerView.addOnItemTouchListener(
                  new RecyclerItemClickListener(this, new RecyclerItemClickListener.OnItemClickListener() {
                      @Override public void onItemClick(View view, int position) {
                          TextView phone = (TextView) view.findViewById(R.id.contact_phone);
                          TextView name = (TextView) view.findViewById(R.id.contact_name);
                          Intent i = new Intent(getApplicationContext(), ContactProfileActivity.class);
                          i.putExtra("selected_user_phone", phone.getText());
                          i.putExtra("selected_user_name", name.getText());
                          startActivity(i);
                      }
                  })
          );
  
          FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                          .setAction("Action", null).show();
              }
          });
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      }
  
      private void sendJsonRequest(String url) {
          if (networkChecker.networkAvailable()) {
              loading.setVisibility(View.VISIBLE);
              RequestQueue requestQueue = VolleySingleton.getsInstance().getmRequestQueue();
  
              StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener&lt;String&gt;() {
                  @Override
                  public void onResponse(String response) {
                      loading.setVisibility(View.GONE);
                      retry.setVisibility(View.GONE);
                      try {
                          JSONArray jsonArray = new JSONArray(response);
  
                          if(jsonArray != null){
                              for (int i = 0; i &lt; jsonArray.length(); i++) {
                                  JSONObject currentContact = jsonArray.getJSONObject(i);
  
                                  String name = currentContact.getString("name");
                                  String phone = currentContact.getString("phone");
                                  String city = currentContact.getString("city");
                                  String address = currentContact.getString("address");
                                  Boolean verified = currentContact.getBoolean("verified");
  
                                  Contact contact = new Contact(name, phone, city, address, verified);
  
                                  contactArrayList.add(contact);
  
                              }
                              adapter.setContactsList(contactArrayList);
                          }
                          else{
                              alertHelper.displayDialog("No Contacts Found.");
                          }
                      }catch (Exception e){
                          retry.setVisibility(View.VISIBLE);
                      }
                  }
              }, new Response.ErrorListener() {
                  @Override
                  public void onErrorResponse(VolleyError error) {
                      loading.setVisibility(View.GONE);
                      retry.setVisibility(View.VISIBLE);
                      if (error instanceof TimeoutError || error instanceof NoConnectionError) {
                          alertHelper.displayDialog(getString(R.string.connection_failed));
                      } else {
                          alertHelper.displayDialog(error.toString());
                      }
                  }
              });
  
              requestQueue.add(stringRequest);
  
          } else {
              alertHelper.displayDialog(getString(R.string.network_not_available));
              retry.setVisibility(View.VISIBLE);
          }
      }
  
  
      @Override
      public void onClick(View v) {
          switch (v.getId()){
              case R.id.tryAgainButton:
                  sendJsonRequest(url);
                  break;
          }
      }
  }
  </code></pre>
  
  <blockquote>
    <p>And this is my xml layout</p>
  </blockquote>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"
      tools:context="com.pinesofts.quickcontact.MyContactsActivity"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/AppTheme.AppBarOverlay"&gt;
  
          &lt;android.support.v7.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="?attr/colorPrimary"
              app:popupTheme="@style/AppTheme.PopupOverlay" /&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          android:gravity="center"&gt;
  
          &lt;RelativeLayout
              android:id="@+id/loadingPanel"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:visibility="gone"
              android:gravity="center" &gt;
  
              &lt;ProgressBar
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:indeterminate="true" /&gt;
          &lt;/RelativeLayout&gt;
  
          &lt;RelativeLayout
              android:id="@+id/retry"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:visibility="gone"
              android:gravity="center" &gt;
  
              &lt;TextView
                  android:id="@+id/retryText"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="@string/try_again_text"/&gt;
  
              &lt;Button
                  android:id="@+id/tryAgainButton"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_below="@id/retryText"
                  android:text="Try Again"/&gt;
          &lt;/RelativeLayout&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;include layout="@layout/content_my_contacts" /&gt;
  
      &lt;android.support.design.widget.FloatingActionButton
          android:id="@+id/fab"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="bottom|end"
          android:layout_margin="@dimen/fab_margin"
          android:src="@android:drawable/ic_dialog_email" /&gt;
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>