List of usage examples for android.widget ProgressBar incrementProgressBy
public synchronized final void incrementProgressBy(int diff)
Increase the progress bar's progress by the specified amount.
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; }