I'm trying to implement a recyclerView showing the progress of some Activities, I decided to use android ProgressBar to represent the progress.
The problem is that the progressBar View does not hold the represented data when i set the progress in onBindViewHolder() or does even show at all sometimes.
I tried some suggestions, e.g. setting the visibility and "setIndeterminate()" in a separate AsyncTask, nothing works.
PS: I'm using a custom drawable, but it does work also with normal Horizontal ProgressBar.
Screenshot of the preview in Android Studio :
#Override
public void onBindViewHolder(ObjectivesViewHolder holder, int position) {
Objective objective = objectives.get(position);
holder.objectiveTextView.setText(objective.getObjectiveTitle());
holder.goalTextView.setText(objective.getGoal() + "");
holder.achievedTextView.setText(String.valueOf(objective.getAchieved()));
new pbUiThread(holder.objectiveProgressBar).execute();
holder.objectiveProgressBar.getProgressDrawable().mutate();
holder.objectiveProgressBar.setProgress((int)objective.getProgress());
if (objective.isDone()) holder.objectivesRow.setAlpha((float) 0.3);
else holder.objectivesRow.setAlpha((float) 1.0);
}
AsyncTask:
public class pbUiThread extends AsyncTask<ProgressBar, Void, Void> {
ProgressBar progressBar;
public pbUiThread(ProgressBar progressBar) {
this.progressBar = progressBar;
}
#Override
protected Void doInBackground(ProgressBar... progressBars) {
progressBar.setVisibility(View.VISIBLE);
progressBar.setIndeterminate(false);
return null;
}
}
ProgressBar in the XML Layout
<ProgressBar
android:id="#+id/objectiveProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginVertical="10dp"
android:layout_marginHorizontal="20dp"
android:max="100"
android:progress="50"
android:visibility="visible"
android:progressDrawable="#drawable/pb_circle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
I used the same layout in another Fragment without RecyclerView and it works like it should.
Any Help ?
Update:
After hours of debugging i found that the problem was in my data modelI have set the progress field to be ignored by the DB using Room's #Ignore annotation since I thought i only need it for the UI)
#Ignore
private float progress;
PS: I'm still kept a handler to update the progress
new Handler().post(new Runnable() {
#Override
public void run() {
holder.objectiveProgressBar.setProgress(progress);;
}
});
you shouldnt save progress in your view especially in recycler view because it will be reused other information will be set to it and your information will be lost. instead try save it in any model that makes sense and set progress from that model in onBindViewHolder.
Related
This question already has answers here:
ProgressDialog is deprecated.What is the alternate one to use?
(22 answers)
Closed 4 years ago.
Since the ProgressDialog is deprecated from the Android version O, I'm still finding a better way out to do my task. The task is to move from my activity to the fragment. Everything is working fine but the progressdialog is not visible. I've tried implementing it but... the progressdialog doesn't work.
It seems the progressbar would work but still not working. I need a progressdialog because it is simply easy for me to set my title and the message. I need a spinner progressDialog but don't know how to do it. Here is one of my work but not implementing :
Java Class
ublic class SaveVideo extends AppCompatActivity {
private Button button;
private ProgressDialog mProgressDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_save_video);
mProgressDialog = new ProgressDialog(this);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.back);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
button = (Button) findViewById(R.id.saveVideo);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//where it must be seen when the button is pressed
mProgressDialog.setTitle("Title");
mProgressDialog.setMessage("Message");
mProgressDialog.show();
Intent intent = new Intent(SaveVideo.this,MainActivity.class);
intent.putExtra("change",2);
startActivity(intent);
//as soon as the page moves from this to another fragment
mProgressDialog.dismiss();
}
});
}
I'm new to Android Version O. Any help would give me new thing to learn!
As it is mentioned in Android O documentation:
This class was deprecated in API level 26. ProgressDialog is a modal
dialog, which prevents the user from interacting with the app. Instead
of using this class, you should use a progress indicator like
ProgressBar, which can be embedded in your app's UI. Alternatively,
you can use a notification to inform the user of the task's progress.
You can create a custom view with TextView and ProgressBar and manage its visibilty.
You can use this library also because it is using AlertDialog instead of ProgressDialog.
ProgressBar is very simple and easy to use,
first step is that you can make xml layout of the dialog that you want to show, let say we name this layout
layout_loading_dialog.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="20dp">
<ProgressBar
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:gravity="center"
android:text="Please wait! This may take a moment." />
</LinearLayout>
next step is create AlertDialog which will show this layout with ProgressBar
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setCancelable(false); // if you want user to wait for some process to finish,
builder.setView(R.layout.layout_loading_dialog);
AlertDialog dialog = builder.create();
now all that is left is to show and hide this dialog in our click events
like this
progress_dialog.show(); // to show this dialog
progress_dialog.dismiss(); // to hide this dialog
and thats it, it should work, as you can see it is farely simple and easy to implement ProgressBar (like ProgressDialog) instead of deprecated ProgressDialog.
now you can show/dismiss this dialog box in either Handler or ASyncTask, its up to your need, hope you can use this to solve your problems, cheers
Yes, API level 26 it's deprecated, Better you can use progressbar only.
Use this code snippet for creating programmatically:
ProgressBar progressBar = new ProgressBar(activity, null, android.R.attr.progressBarStyleSmall);
Just for future reference, change the android.R.attr.progressBarStyleSmall to android.R.attr.progressBarStyleHorizontal.
Maybe this guide could help you.
I hope this may help you.
This class was deprecated in API level 26.
ProgressDialog is a modal dialog, which prevents the user from
interacting with the app. Instead of using this class, you should use
a progress indicator like ProgressBar, which can be embedded in your
app's UI. Alternatively, you can use a notification to inform the user
of the task's progress.
https://developer.android.com/reference/android/app/ProgressDialog.html
You need to create a custom XML layout file with ProgressBar on it and show that instead. I've been using a library like https://github.com/Q115/DelayedProgressDialog to get this simple behavior.
Usage:
DelayedProgressDialog progressDialog = new DelayedProgressDialog();
progressDialog.show(getSupportFragmentManager(), "tag");
You can use ProgressBar instead of ProgressDialog.
Create a ProgressBar inside a custom dialog with TextView and other widgets you need.
If anyone insists on having a progress dialog, in my case I opted for a progress bar inside an alert dialog. You can use the following code to get started.
My case was simple because I just needed an indeterminate progressbar. For a full fledged version you'll have to encapsulate it into a class and access the Bar.
private AlertDialog Create_Indeterminate_HorizontalProgressBar_AlertDialog(
Context context, String title, String message)
{
final ProgressBar progressBar =
new ProgressBar(
context,
null,
android.R.attr.progressBarStyleHorizontal);
progressBar.setLayoutParams(
new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
progressBar.setIndeterminate(true);
final LinearLayout container =
new LinearLayout(context);
container.addView(progressBar);
int padding =
getDialogPadding(context);
container.setPadding(
padding, (message == null ? padding : 0), padding, 0);
AlertDialog.Builder builder =
new AlertDialog.Builder(context).
setTitle(title).
setMessage(message).
setView(container);
return builder.create();
}
private int getDialogPadding(Context context)
{
int[] sizeAttr = new int[] { android.support.v7.appcompat.R.attr.dialogPreferredPadding };
TypedArray a = context.obtainStyledAttributes((new TypedValue()).data, sizeAttr);
int size = a.getDimensionPixelSize(0, -1);
a.recycle();
return size;
}
Note: If you're wondering why the Bar is in a container: I just couldn't get the padding to work on the Bar having to put in on the container instead.
This is what i managed to put together since the class has been deprecated in Android Oreo (API 26 +).
In the Xml File (whatever layout file):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:padding="13dp"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:visibility="gone"
android:layout_marginTop="5dp"
android:id="#+id/top_progressBar"
style="#style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_height="wrap_content"
android:indeterminateTintMode="src_in"
android:indeterminateTint="#color/white"
android:indeterminate="true" />
<TextView
android:layout_width="wrap_content"
android:text="Loading..."
android:textAppearance="?android:textAppearanceSmall"
android:layout_gravity="center_vertical"
android:id="#+id/loading_msg"
android:layout_toEndOf="#+id/loader"
android:layout_height="wrap_content" />
<ProgressBar
android:visibility="gone"
android:layout_marginTop="2dp"
android:id="#+id/down_progressBar"
style="#style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_height="wrap_content"
android:indeterminateTintMode="src_in"
android:indeterminateTint="#color/white"
android:indeterminate="true" />
</LinearLayout>
in the sample above, i have thought of a scroll situation say your view is long hence the two progress bars.
in the Java file sample :
public class GetUserDetails extends AppCompatActivity {
private ProgressBar topProgressBar, downProgressBar;
private ProgressDialog progressDialog;
#Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate ( savedInstanceState );
setContentView ( R.layout.activity_get_user_details );
//initilise the progressbar views and progress dialog object
topProgressBar = findViewById ( R.id.top_progressBar );
downProgressBar = findViewById ( R.id.down_progressBar );
if ( Build.VERSION.SDK_INT < 26 ) {
progressDialog = new ProgressDialog ( this );
} else {
topProgressBar.setIndeterminate ( true );
downProgressBar.setIndeterminate ( true );
}
}
private void showProgressDialog (final boolean isToShow) {
if ( Build.VERSION.SDK_INT < 26 ) {
if ( isToShow ) {
progressDialog.setMessage ( "Processing ...Please wait." );
progressDialog.setCancelable ( false );
if ( ! progressDialog.isShowing () ) {
progressDialog.show ();
}
} else {
if ( progressDialog.isShowing () ) {
progressDialog.dismiss ();
}
}
} else {
/* this is Android Oreo and above*/
if ( isToShow ) {
topProgressBar.setVisibility ( View.VISIBLE );
downProgressBar.setVisibility ( View.VISIBLE );
getWindow ().setFlags ( WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE );
} else {
topProgressBar.setVisibility ( View.GONE );
downProgressBar.setVisibility ( View.GONE );
getWindow ().clearFlags ( WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE );
}
}
}
}
Well , this is my hack so i hope it helps.
The ProgressDialog in your example won't ever be visible because you call dismiss() right after show(). The creation of an Intent and call to startActivity() are not blocking: Basically you just schedule a switch to the other activity to be performed "soon".
You have to move the dismiss() call to your activity's onStop:
#Override
protected void onStop()
{
super.onStop();
mProgressDialog.dismiss();
}
Furthermore one might ask: Why does switching from one activity to the other take so long in this case? I guess that your MainActivity does some heavy work in its onCreate / onStart / onResume methods. A better way of handling that might be to put all that work into a separate thread.
I am using a custom ProgressBar. Now while a task is going on, I am showing the progress bar, but user can still interact with the views and controls.
How do I disable the user interaction on whole view just like a ProgressDialog does , when it is visible.
Do I need to use a transparent view on top of main view and show the progress bar on that view and hide that view once a task is completed.
Or just get the id of my parentView and set it disabled ? But then I won't be able to dim the background, just like what happens when a dialog appears on the view/Activity/Fragment. Right?
I just want to know the way to disallow the user from any interaction while the progressbar is visible.
Thanks
Your question: How to disable the user interaction while ProgressBar is visible in android?
To disable the user interaction you just need to add the following code
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
To get user interaction back you just need to add the following code
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
Here is an example:
Note:I am giving you just an example to show how to disable or retain user interaction
Add a progress bar in your xml.Something like this
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressBar"
android:visibility="gone"/>
In MainActivity when a button pressed you show the progressbar and disable the user interaction.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mImageView = (ImageView) findViewById(R.id.imageView);
mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
mImageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mProgressBar.setVisibility(View.VISIBLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
}
});
}
And when user backPressed you remove the progressbar again retain the user interaction.Something like this
#Override
public void onBackPressed() {
super.onBackPressed();
mProgressBar.setVisibility(View.GONE);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
}
If you want to add a feature of disable and greyed out display, you need to add in your xml layout file a linear layout that fills the parent. Set its background to #B0000000 and its visibilty to GONE. Then programmatically set its visibility to VISIBLE.
Hope this help!
I have fixed this issue by adding root layout to the ProgressBar.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:clickable="true"
android:gravity="center"
android:visibility="gone"
android:id="#+id/progress">
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="true"
android:indeterminateTintMode="src_atop"
android:indeterminateTint="#color/primary"/>
</LinearLayout>
Made the root layout clickable
android:clickable="true"
NOTE: In my main view, I had RelativeLayout as root and have added above-mentioned code inside the root layout at the last position (last child).
Hope this helps!!
just set:
android:clickable="true"
in your xml
<ProgressBar...
Only this makes magic!
To extend (pun intended) on the accepted Answer :
When you use kotlin you can use extension functions. That way you have a quick and nice looking method for blocking and unblocking UI.
fun AppCompatActivity.blockInput() {
window.setFlags(
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
}
fun AppCompatActivity.unblockInput() {
window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
}
fun AppCompatActivity.blockInputForTask(task: () -> Unit) {
blockInput()
task.invoke()
unblockInput()
}
You can use the blocking and unblocking functions in your activity. Also, you can add more functionality like showing a Toast or something.
When using it in a custom view or any other view, you can simply cast the context to activity and use the functions.
Use blockInputForTask to surround simple linear tasks and blockInputand unblockInput when they are needed in different scopes.
You can use blockInputForTask like this:
blockInputForTask {
// Your lines of code
// Can be multiple lines
}
Use document default method progressbar.setCancelable(false)
Make a dialog with transparent background. The issue with getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); is that when app will go in background and come back user will be able to interact with UI components, a lot more handling. So for blocking UI make a transparent dialog and if you want to set time for hide/show. Do this in a runnable thread. So the solution will be
public class TransparentDialogHelper {
private Dialog overlayDialog;
#Inject
public TransparentDialogHelper() {
}
public void showDialog(Context context) {
if (AcmaUtility.isContextFinishing(context)) {
return;
}
if (overlayDialog == null) {
overlayDialog = new Dialog(context, android.R.style.Theme_Panel);
overlayDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED);
}
overlayDialog.show();
}
public void hideDialog() {
if (overlayDialog == null || AcmaUtility.isContextFinishing(overlayDialog.getContext())) {
return;
}
overlayDialog.cancel();
}
}
-------- Timer
Handler handler = new Handler();
handler.postDelayed( () -> {
view.hideProgress();
}, 2000);
Make your parent layout as Relative Layout & add this :
<RelativeLayout ... >
<other layout elements over which prog bar will appear>
<RelativeLayout android:id="#+id/rl_progress_bar"
android:layout_width="match_parent" android:clickable="true"
android:layout_height="match_parent" >
<ProgressBar android:id="#+id/pb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminateOnly="true"
style="#android:style/Widget.DeviceDefault.ProgressBar"
android:theme="#style/AppTheme.MyProgressBar"
/>
</RelativeLayout>
If you have floating buttons in your UI, they still grab all the focus & remain clickable when the progress bar is visible. for this use : (when your prog bar is visible & re-enable them when you make your prog bar invisible/gone)
fb.setEnabled(false);
I have a custom component that extends RelativeLayout which in turns holds a GridLayout(named mFormLayout). I have a public method that adds two spinners with their proper adapter source and an imageview which acts as a button to remove rows.
public class EditableTwinSpinnerGridForm extends EditableGridForm
{
public void addTwinSpinnerRow(final Locale.MapKey spinner1DefVal, final Locale.MapKey spinner2DefVal)
{
Spinner spinner1 = createSpinner(mTSP.getFirstSpinnerRes(), spinner1DefVal.getId());
spinner1.setOnItemSelectedListener(mTSP.getIsl());
Spinner spinner2 = createSpinner(mTSP.getSecondSpinnerRes(), spinner2DefVal.getId());
ImageView rmvBtn = createRemoveBtn();
mFormLayout.addView(spinner1);
mFormLayout.addView(spinner2);
mFormLayout.addView(rmvBtn);
}
}
For some reason, this method works when I am adding rows from a call to onCreate in an activity, but when I am calling this method after the activity is created(from an onclicklistener) the Spinners are either not there or only one of them shows up. They do take the space because I see the row and the removable image view.
I have also noticed that when I focus on a EditText in the same activity and the keyboard pops up, the added spinners show up when I press back to remove the keyboard.
Here's the code I use to create a spinner :
protected Spinner createSpinner(Integer spinnerSrc, String defaultSpinnerValue)
{
Spinner spinner = new Spinner(mCtx, Spinner.MODE_DIALOG);
// Setting the bg color to the containing color to remove the spinner arrow.
spinner.setBackgroundResource(R.color.container_bg);
SparseArray<Phrase> map = Locale.getInstance().getMap(spinnerSrc);
PhraseArrayAdapter adapter = createSpinnerFromMap(spinnerSrc);
spinner.setAdapter(adapter);
if (defaultSpinnerValue.equals(Utilities.EMPTY_STRING) || defaultSpinnerValue.isEmpty())
{
throw new IllegalStateException();
}
else
{
Utilities.getInstance().setMapSpinnerPosByValue(map, defaultSpinnerValue, spinner);
}
adapter.setDropDownViewResource(R.layout.editable_spinner_dropdown_item);
setSpinnerLayoutParams(spinner);
return spinner;
}
protected void setSpinnerLayoutParams(Spinner spinner)
{
GridLayout.LayoutParams lp = createDefaultGridParams();
lp.setGravity(Gravity.FILL_HORIZONTAL);
lp.width = 250;
lp.rightMargin = 0;
spinner.setLayoutParams(lp);
}
The code works when the activity is loaded so I'm a bit stumped. I looked around and some people suggested I set LayoutParams in addView, but why would this method work in onCreate, but not afterwards?
Here's what's happening visually(The first three rows are added from a loop in onCreate(), the two second ones are added by pressing "Add +"). As you can see the second spinner isn't showing up, sometimes both aren't showing up. I also tried calling invalidate and requestLayout to no avail.
I had looked into the invalidate method, here's where it is located currently :
public abstract class EditableForm extends RelativeLayout implements ObservableInt
{
private class OnAddClicked implements OnClickListener
{
#Override
public void onClick(View v)
{
onAddClicked(v);
EditableForm.this.invalidate();
mFormLayout.invalidate();
}
}
}
Which calls(In a subclass of EditableGrid) :
#Override
protected void onAddClicked(View clickedView)
{
addTwinSpinnerRow();
notifyObservers(new ObservableData(EDITABLE_ADD_GRID_CLICKED, null));
}
protected void addTwinSpinnerRow()
{
Locale.MapKey v1 = Locale.getInstance().getMap(mTSP.getFirstSpinnerRes()).get(0).getMapId();
Locale.MapKey v2 = Locale.getInstance().getMap(mTSP.getSecondSpinnerRes()).get(0).getMapId();
addTwinSpinnerRow(v1, v2);
}
Have you tried calling the Invalidate method of the container view rather than the added view?
Most likely the views you are adding are there, they just need to be drawn which is suggested by your keyboard hide/show difference. Does rotating the device also cause them to appear? If so, this again suggests that you need to redraw your custom layout.
When it's necessary to execute invalidate() on a View?
I have a ListView in my RelativeLayout that is supposed to be hidden during a search is executed. Therefore I implemented the following code:
mProgressView.setVisibility(View.VISIBLE);
mSearchListView.setVisibility(View.INVISIBLE);
mSearchAdapter.search(query).onSuccess(new Continuation<Set<Integer>, Object>() {
#Override
public Object then(final Task<Set<Integer>> task) throws Exception {
runOnUiThread(new Runnable() {
#Override
public void run()
mSearchAdapter.notifyDataSetChanged();
mProgressView.setVisibility(View.INVISIBLE);
mSearchListView.setVisibility(View.VISIBLE);
}
});
return null;
}
});
Unfortunately, the ListView stays visible. The ProgressView start to spin successfully but the list view remains visible. Any hints on what to do?
When you say it stays 'visible' do you mean you see data in the listview or just that some space seems to be occupied by an invisible listview?
If the latter is the case then you should try making the listview GONE as -
mSearchListView.setVisibility(View.GONE);
instead of making it invisible
I need to display progress icon in button so that user can interact other GUI elements while background task is processing.
I have searched in Android developer site and found that we can use animated drawables but don't know how to use them. Please advise on the same.
The very simple way to do this without using the animated drawable is to use "PregressBar" component in the design layout xml. When u need to show it, just set it's visibility property to visible and when you need to hide it, u can set it's visibility property to GONE. But remember this is UI task so when u need to do this with non-UI thread, u need to use Handler to set the status of "ProgressBar" component at runtime.
Below id the component in the layout file.
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ProgressBar>
Below is the code written in java file
ProgressBar prg;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
prg=(ProgressBar)findViewById(R.id.ProgressBar1);
prg.setVisibility(ProgressBar.GONE);
}
public void start_background_process()
{
// starting the process
prg.setVisibility(ProgressBar.VISIBLE);
new Thread(new Runnable()
{ public void run()
{
// Do your background stuff here which takes indefinite time
mHandlerUpdateProgress.post(mUpdateUpdateProgress);
}
} ).start();
}
final Handler mHandlerUpdateProgress= new Handler();
final Runnable mUpdateUpdateProgress = new Runnable() {
public void run() {
// ending the process
prg.setVisibility(ProgressBar.GONE);
}
};
If the default progress indicator is good enough for you (i.e. the spinning wheel), then you can just use ProgressBar. To change it from a normal progress bar to a spinning wheel, use progressBar.setIndeterminate(true).