title: Adding a progress dialog to app whilst loading data from a volley
body: <p>I'm trying to add a progress dialog to my app whilst it loads data from a volley. I've tried a few ways but i'm currently following this tutorial <a href="http://www.androidhive.info/2014/07/android-custom-listview-with-image-and-text-using-volley/" rel="nofollow">http://www.androidhive.info/2014/07/android-custom-listview-with-image-and-text-using-volley/</a> and was hoping it would look like the example used there. Please could someone take a look at my code so far! i'm not getting errors but it is not displaying like the example. As you can see i've created the method in onCreate and called the hide method in my response listeners.</p>
  
  <p>Thank you!</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      private List&lt;NewsRecord&gt; newsListData = new ArrayList&lt;NewsRecord&gt;();
  
      private GridView newsListView;
  
      private NewsListAdapter adapter;
  
      LinearLayout layout;
  
      private ProgressDialog pDialog;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          GridView newsListView = (GridView) findViewById(R.id.newsFeedList);
          adapter = new NewsListAdapter(this, R.layout.adapter_news_list, newsListData, this);
  
          layout = (LinearLayout) findViewById(R.id.progressbar_view);
          newsListView.setAdapter(adapter);
  
          pDialog = new ProgressDialog(this);
          // Showing progress dialog before making http request
          pDialog.setMessage("Loading Articles...");
          pDialog.show();
  
          newsListView.setOnItemClickListener(itemClicked);
  
          nextStart = 0;
          updateListData(nextStart, 20);
  
      }
  
      public int nextStart = 0;
  
      public void updateListData(int StartPoint, int count){
          String url = "http://www.efstratiou.info/projects/newsfeed/getList.php?start=" + StartPoint + "&amp;count=" + count;
  
          EDANewsApp app = EDANewsApp.getInstance();
  
          JsonArrayRequest jsonRequest = new JsonArrayRequest(url, listener, errorListener);
          app.requestQueue.add(jsonRequest);
  
          nextStart +=count;
      }
  
      @Override
      public boolean onCreateOptionsMenu (Menu menu){
          MenuInflater inflater = getMenuInflater();
          inflater.inflate(R.menu.main_menu, menu);
          return true;
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
          hidePDialog();
      }
  
      private void hidePDialog() {
          if (pDialog != null) {
              pDialog.dismiss();
              pDialog = null;
          }
      }
  
      public boolean onOptionsItemSelected(MenuItem item){
          switch (item.getItemId()) {
              case R.id.action_about:
                  Intent intent = new Intent(this, AboutActivity.class);
                  startActivity(intent);
                  return true;
              case R.id.action_search:
                  return true;
              case R.id.action_settings:
                  return true;
              default:
                  return super.onOptionsItemSelected(item);
              }
      }
  
      AdapterView.OnItemClickListener itemClicked = new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
              Intent intent = new Intent(MainActivity.this, NewsItemActivity.class);
  
              intent.putExtra("newsItemId", newsListData.get(position).recordId);
  
              startActivity(intent);
          }
      };
  
      private SearchView.OnQueryTextListener searchQueryListener = new SearchView.OnQueryTextListener() {
          @Override
          public boolean onQueryTextSubmit(String query) {
              Intent searchIntent = new Intent(MainActivity.this, SearchResultsActivity.class);
              searchIntent.putExtra("query", query);
              return true;
          }
  
          @Override
          public boolean onQueryTextChange(String newText) {
             return false;
          }
      };
  
      //Listeners
      Response.Listener&lt;JSONArray&gt; listener = new Response.Listener&lt;JSONArray&gt;() {
          @Override
          public void onResponse(JSONArray response) {
              //we successfully received the JSONArray
              //Here we will extract the data and use it in our app
  
              //Clear the dataset before loading new data
            //  newsListData.clear();
              //Go through all the JSON objects
              for (int i = 0; i &lt; response.length(); i++) {
  
                  try {
                      //Get one JSON object
                      JSONObject jsonObj = response.getJSONObject(i);
  
                      //Put JSON data in a Java object
                      NewsRecord record = new NewsRecord();
                      record.recordId = jsonObj.getInt("record_id");
                      record.title = jsonObj.getString("title");
                      record.date = jsonObj.getString("date");
                      record.shortInfo = jsonObj.getString("short_info");
                      record.imageUrl = jsonObj.getString("image_url");
  
                      newsListData.add(record);
  
                  } catch (JSONException e) {
                      e.printStackTrace();
                  }
  
              }
              adapter.notifyDataSetChanged();
              hidePDialog();
          }
      };
  
      Response.ErrorListener errorListener = new Response.ErrorListener() {
          @Override
          public void onErrorResponse(VolleyError error) {
              //There was an error in the communication
              //We can notify the user about it
              hidePDialog();
  
          }
      };
  
  }
  </code></pre>
  
  <p>activity_main.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/newsListItem"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      tools:context=".MainActivity"&gt;
  
      &lt;LinearLayout
          android:id="@+id/progressbar_view"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:gravity="center_horizontal"
          android:orientation="vertical" &gt;
  
          &lt;LinearLayout
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:gravity="center_horizontal"
              android:orientation="horizontal" &gt;
  
              &lt;ProgressBar
                  style="?android:attr/progressBarStyle"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center_vertical|center_horizontal" /&gt;
  
              &lt;TextView
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center_vertical|center_horizontal"
                  android:text="Loading data..." /&gt;
          &lt;/LinearLayout&gt;
  
          &lt;View
              android:layout_width="fill_parent"
              android:layout_height="1dp"
              android:background="#C0C0C0" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;GridView
          android:id="@+id/newsFeedList"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:verticalSpacing="0dp"
          android:horizontalSpacing="0dp"
          android:stretchMode="columnWidth"
          android:numColumns="2"/&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>