title: How to show a ProgressBar example with percentage in Android
body: <p>I have a task to add a <code>ProgressBar</code> with percentage values on it to show a value when the user wants to predict something. I'm not using <code>ProgressDialog</code> since it's now deprecated. Here, the percentage value depends on how long it is from start a request until it's completed. I'm using <code>Volley</code> to fetch data from server. </p>
  
  <p>Here goes a sample image of what I'm trying to achieve: </p>
  
  <p><a href="https://i.stack.imgur.com/GNICx.png" rel="noreferrer"><img src="https://i.stack.imgur.com/GNICx.png" alt="ProgressBar Percentage Value"></a></p>
  
  <p>i already did like this</p>
  
  <p>i have implement a horizontal progress bar inside an alert dialog (i'm using this way because progress dialog is deprecated). i want to setProgress the progress bar like this.</p>
  
  <pre><code>public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      view =  inflater.inflate(R.layout.fragment_result_prediction, container, false);
      predictProgress = (ProgressBar) view.findViewById(R.id.progressbarPredict);
      AlertDialog.Builder(view.getContext());
      builder.setCancelable(false); // if you want user to wait for some process to finish,
      View v = inflater.inflate(R.layout.layout_loading_dialog, null);
      builder.setView(v);
      final AlertDialog dialog = builder.create();
      submitPredictPlant.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
                  dialog.show();
                  predictProgress.setProgress(25);
                  predictProgress.setProgress(50);
                  predictProgress.setProgress(75);
                  predictProgress.setProgress(100);
                  dialog.dismiss();
  </code></pre>
  
  <p>i want to dismiss the dialog when the progress is 100. but this give an error like</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ProgressBar.setProgress(int)' on a null object reference
  </code></pre>
  
  <p>i already refer the progress bar from layout_loading_dialog that is used in builder.setview.</p>
  
  <p>here is the layout_loading_dialog.xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical"
  android:padding="20dp"&gt;
  &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:layout_weight="4"
      android:gravity="center"
      android:text="Please wait! This may take a moment." /&gt;
  
  &lt;ProgressBar
      android:layout_width="match_parent"
      android:id="@+id/progressbarPredict"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      style="?android:attr/progressBarStyleHorizontal"/&gt;
  </code></pre>
  
  <p></p>