title: Android Basic Activity & ListView - Progress Bar Not visible
body: <p>I have an Android activity as basic activity which have below layout - </p>
  
  <p><a href="https://i.stack.imgur.com/IxI78.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IxI78.png" alt="Layout"></a></p>
  
  <p>And below is the xml for the layout</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout 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:id="@+id/activity_read_contacts"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context="au.com.savedme.ReadContacts"&gt;
  
  &lt;ListView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:id="@+id/readContactLv" /&gt;
  
  &lt;ProgressBar
      style="?android:attr/progressBarStyle"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/readContactPb"
      android:layout_alignParentBottom="false"
      android:layout_alignParentRight="false"
      android:layout_centerVertical="true"
      android:layout_centerHorizontal="true" /&gt;
  
  &lt;android.support.design.widget.FloatingActionButton
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:clickable="true"
      app:fabSize="mini"
      app:srcCompat="@mipmap/ic_cloud_upload_white_24dp"
      android:id="@+id/readContactFab"
      android:layout_alignParentBottom="true"
      android:layout_alignParentRight="true" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>I am starting this activity from another activity. My goal is to make progress bar visible in onCreate method and then loading the listview, once the list view is populated with items I want to make the progress bar invisible. </p>
  
  <p>My questions are</p>
  
  <ul>
  <li>if I start populating the list view the progress bar is not visible at all no matter what I try.</li>
  <li>if I skip populating the list view the progress bar is visible clearly.</li>
  <li>if I am populating the list view there is a significant delay in navigation from previous activity and the screen just freezes and gets black(And Blank) and once the list is populated it comes back, which doesn't give any visual clue to user that something happening (not desired).</li>
  </ul>
  
  <p>What should I do to prevent this, below is my onCreate method - </p>
  
  <pre><code> @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_read_contacts);
  
      pb = (ProgressBar) findViewById(R.id.readContactPb);
      pb.setVisibility(View.VISIBLE);
  
      // Variable initialisations
      contactList = new ArrayList&lt;&gt;();
      contactListTosave = new ArrayList&lt;&gt;();
      mDatabase = FirebaseDatabase.getInstance().getReference();
      userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
      mContactListView = (ListView) findViewById(R.id.readContactLv);
      mContactListView.setOnItemClickListener(onClickListener);
      FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.readContactFab);
      fab.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              for (Contact contactToSave:contactListTosave){
                  mDatabase.child("contacts").child(userId).child(contactToSave.getFirstName()).setValue(contactToSave);
              }
              Intent i = new Intent(getApplicationContext(),ContactList.class);
              startActivity(i);
          }
      });
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
      if (mAdapter == null) {
          mAdapter = new ContactArrayAdapter(ReadContacts.this, 0, contactList);
          mContactListView.setAdapter(mAdapter);
      }
      checkPermissionToReadContact();
  }
  </code></pre>
  
  <p>And below is the code for my listAdapter -</p>
  
  <pre><code>import android.content.Context;
  import android.os.Build;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.TextView;
  
  import java.util.ArrayList;
  import java.util.List;
  
  /**
  * Created by AppsWise on 15/10/16.
  */
  
  public class ContactArrayAdapter extends ArrayAdapter&lt;Contact&gt; {
      private Context context;
      private List&lt;Contact&gt; contactsProperties;
      private String TAG = "ContactArrayAdapter";
  
  //constructor, call on creation
  public ContactArrayAdapter(Context context, int resource, ArrayList&lt;Contact&gt; objects) {
      super(context, resource, objects);
      this.context = context;
      this.contactsProperties = objects;
  }
  
  // Called when rendering the view
  public View getView(int position, View convertView, ViewGroup parent) {
      // get properties we are displaying
      Contact contact = contactsProperties.get(position);
  
      //Get inflater and inflate the XML layout for each item
      LayoutInflater inflater = (LayoutInflater) context.getSystemService(MainActivity.LAYOUT_INFLATER_SERVICE);
      View view = inflater.inflate(R.layout.contact_item, null);
      TextView nameText = (TextView) view.findViewById(R.id.nameText);
      TextView contactName = (TextView) view.findViewById(R.id.contactName);
      TextView number = (TextView) view.findViewById(R.id.phoneText);
  
      String completeName = "";
      if(contact.getFirstName()!=null){
          completeName = contact.getFirstName();
      }
      if(contact.getLastName()!=null){
          completeName += "  "+contact.getLastName();
      }
      if (completeName!=null &amp;&amp; completeName.trim().length()&gt;0) {
          if (nameText!=null) {
              nameText.setText(completeName.substring(0,1).toUpperCase());
          }
          contactName.setText(completeName);
          if(Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M &amp;&amp; contact.getIsUploaded() ){
              nameText.setBackgroundColor(context.getColor(R.color.colorAccent));
          }
      }
      number.setText(contact.getPhone());
      return view;
  }
  </code></pre>
  
  <p>}</p>