Example usage for android.widget ProgressBar incrementProgressBy

List of usage examples for android.widget ProgressBar incrementProgressBy

Introduction

In this page you can find the example usage for android.widget ProgressBar incrementProgressBy.

Prototype

public synchronized final void incrementProgressBy(int diff) 

Source Link

Document

Increase the progress bar's progress by the specified amount.

Usage

From source file:app.android.example.com.commontcents.ListContentFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View recyclerView = inflater.inflate(R.layout.item_list, container, false);

    final ProgressBar progressBar = (ProgressBar) recyclerView.findViewById(R.id.progress_bar);
    progressBar.setScaleY(3f);/*w  ww.  ja  va2  s  . co m*/

    final Handler mHandler = new Handler();

    mHandler.post(new Runnable() {
        public void run() {
            progressBar.incrementProgressBy(10 * poolCounter.getCount());
            progressBar.setProgress(progressBar.getProgress());
        }
    });

    return recyclerView;
}

From source file:org.tomasdavid.vehicleroutingproblem.tasks.ProgressBarTask.java

/**
 * {@inheritDoc}//from  w ww.j  a va  2s  .c o  m
 */
@Override
protected Void doInBackground(Integer... params) {

    // initialize progress bar
    progress = 0;
    ProgressBar progressBar = (ProgressBar) fragment.getActivity().findViewById(R.id.progress_bar);
    progressBar.setProgress(progress);

    // while solver task is running change progress every 1 second
    while (fragment.getVrpSolverTask().isRunning() && progress < progressBar.getMax()) {
        try {
            Thread.sleep(SECOND);
        } catch (InterruptedException e) {
            Log.e(TAG, "Thread sleep error.", e);
        }

        if (fragment != null) {
            FragmentActivity activity = fragment.getActivity();
            if (activity != null) {
                progressBar = (ProgressBar) activity.findViewById(R.id.progress_bar);
                if (progressBar != null) {
                    progressBar.incrementProgressBy(1);
                }
            }
        }
        progress++;
    }

    return null;
}