-1

I already know progressBar.setVisibility(View.GONE) can hide the progress bar.

But is it same as the ProgressDialog.dismiss()?

I can only use progressBar due to AsyncTask block Unity(UI) thread issue.

What I want to achieve is to delete it permanently not just hide it for some time.

Community
  • 1
  • 1
AlexWei
  • 1,093
  • 2
  • 8
  • 32
  • Delete it permanently? Why? Just set the visibility. – Xaver Kapeller Feb 24 '16 at 08:13
  • ProgressBar and ProgressDialog are two different things. The first is a view and the second is a Dialog that contains a view. – Doug Stevenson Feb 24 '16 at 08:13
  • @XaverKapeller Because after it show the progress for some time, it is not needed any more. – AlexWei Feb 24 '16 at 08:13
  • first dismiss it by using .dismiss() then set it to null if u wana release it – Nidhin Prathap Feb 24 '16 at 08:14
  • when you do View.GONE, the view is actually removed from the view heirarchy – Bhargav Feb 24 '16 at 08:16
  • Possible duplicate of [Android - dismiss progress bar automatically](http://stackoverflow.com/questions/14854457/android-dismiss-progress-bar-automatically) – Strider Feb 24 '16 at 08:17
  • @Bhargav Yes.But when I set the visibility to true, it will be added again. But I am sure the view will not be used anymore. Is there any way to delete it permanent? – AlexWei Feb 24 '16 at 08:18
  • @AlexWei You don't gain anything by deleting it. As long as you are in the same layout then the `View` is just going to be there. – Xaver Kapeller Feb 24 '16 at 08:20
  • 1
    when you do View.GONE the view IS DELETED from the view hierarchy, only the view object is cached only if you hold a reference to the object in your class, if just assign that ref to null, then its effectively deleting the view, but the xml file will stil contain whatever you typed and since you gave this view an ID, there will be an ID reference to it in the R class, but if you were to create the ProgressBar programatically when you need it, then by removing reference to the progress bar you would be effectively deleting it – Bhargav Feb 24 '16 at 08:21
  • @Bhargav Thanks. This is what I am looking for. – AlexWei Feb 24 '16 at 08:24
  • @AlexWei oops View.GONE apparently doesn't remove it from view hierarchy what you can do to remove it is do `((ViewGroup)mProgressBar.getParent().removeView(mProgressBar))` which would actually remove the view from its parent, make sure the parent is castable to `ViewGroup` – Bhargav Feb 24 '16 at 08:27

2 Answers2

0

ProgressDialog is obviously a dialog so you can dismiss it, but ProgressBar is a view, so it's ok to just hide it using visibility.

Geralt_Encore
  • 3,721
  • 2
  • 31
  • 46
0

when you do View.GONE the view IS DELETED from the view hierarchy, only the view object is cached only if you hold a reference to the object in your class, if just assign that ref to null, then its effectively deleting the view, but the xml file will stil contain whatever you typed and since you gave this view an ID, there will be an ID reference to it in the R class, but if you were to create the ProgressBar programatically when you need it, then by removing reference to the progress bar you would be effectively deleting it

EDIT

oops View.GONE apparently doesn't remove it from view hierarchy what you can do to remove it is do

((ViewGroup)mProgressBar.getParent()).removeView(mProgressBar)

which would actually remove the view from its parent, make sure the parent is castable to ViewGroup

Bhargav
  • 8,118
  • 6
  • 40
  • 63
  • So only call View.Gone doesn't delete itself from the view hierarchy. And I also need to call removeView. Am I correct? – AlexWei Feb 24 '16 at 08:32
  • @AlexWei yes removingView will definitely delete it, setting View.GONE is upto you, but by just doing removeView the view will be removed, which means you dont have to set visibility separately – Bhargav Feb 24 '16 at 10:06