Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I got the answer related to this stuff some days back(but updating it today as got some free time).</p> <p>Here the code that I have used for making this stuff best.I achieved above thing by Custom Dialog.Firstly here the code of activity from which I called the class of Custom Dialog.</p> <pre><code>import android.app.Activity; import android.app.ProgressDialog; import android.os.Bundle; import android.widget.ProgressBar; import android.widget.TextView; public class ProgressThread extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MyDialog dialog = new MyDialog(this); dialog.show(); } } </code></pre> <p>Now the code related to the Custom Dialog. Here I have used <code>ProgressBar &amp; TextViews</code> in CustomDialog &amp; made calculations on basis on download which in turn updates TextViews.The example used here updates the textviews &amp; progressbar in dummy manner.You change that as per your need.</p> <pre><code>import android.app.Dialog; import android.content.Context; import android.graphics.Color; import android.os.Handler; import android.os.Message; import android.widget.ProgressBar; import android.widget.TextView; public class MyDialog extends Dialog { public static final int STATUS_UPDATE = 101; public static final int STATUS_COMPLETE = 100; ProgressBar progressBar; TextView textView; TextView percent; int increment; int progress; public MyDialog(Context context) { super(context); setContentView(R.layout.progressbar); setDialog(); } private void setDialog() { setTitle("Downloading Files...."); textView = (TextView) findViewById(R.id.textProgress); progressBar = (ProgressBar) findViewById(R.id.progress_horizontal); percent = (TextView) findViewById(R.id.textPercentage); percent.setTextColor(Color.WHITE); textView.setTextColor(Color.WHITE); progressBar.setProgressDrawable(getContext().getResources() .getDrawable(R.drawable.my_progress)); progressBar.setIndeterminate(false); // set the maximum value progressBar.setMax(1315); launcherThread(); } private void launcherThread() { LoaderThread loaderThread = new LoaderThread(); loaderThread.start(); LauncherThread launcherThread = new LauncherThread(); launcherThread.start(); } private class LoaderThread extends Thread { @Override public void run() { try { while (progressBar.getProgress() &lt; progressBar.getMax()) { // wait 500ms between each update Thread.sleep(100); increment++; // active the update handler progressHandler.sendEmptyMessage(STATUS_UPDATE); } progressHandler.sendEmptyMessage(STATUS_COMPLETE); } catch (InterruptedException e) { e.printStackTrace(); } } } // handler for the background updating Handler progressHandler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case STATUS_UPDATE: progressBar.setProgress(increment); float value = increment / 1315F; percent.setText(" " + ((int) (value * 100)) + "%"); System.out.println(value * 100); textView.setText(String.valueOf(progressBar.getProgress()) .concat(" / " + progressBar.getMax())); break; case STATUS_COMPLETE: dismiss(); } } }; private class LauncherThread extends Thread { @Override public void run() { progressHandler.sendMessage(progressHandler.obtainMessage()); progressHandler.sendEmptyMessage(0); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload