Reputation: 87
I have created an app where a service runs in the background. When there is progress it will display a toast message, but I want to add a progress bar. Can someone helo me with this?
this is the method which will display the toast message: ( 25% downloaded, 50% and so on)
protected void onProgressUpdate(Integer... progress) {
Log.d("Downloading files",
String.valueOf(progress[0]) + "% downloaded");
Toast.makeText(getBaseContext(),
String.valueOf(progress[0]) + "% downloaded",
Toast.LENGTH_LONG).show();
}
layout of progress bar in activity_main.xml
<ProgressBar
android:id="@+id/p_barr"
android:layout_width="150dp"
android:layout_height="150dp"
style="?android:progressBarStyleHorizontal"
android:progress="5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>
Upvotes: 1
Views: 113
Reputation: 124
it's very simple in your main activity.do
ProgressBar bar;
// in oncreate method
bar=findviewbyid("your progressbar id p_barr ");
bar.setProgress(int);
Upvotes: 3