I have created display using Fragments
, both of which is being populated with data pulled from the internet. While the code itself works as expected without any issues, one of a Fragments (implemented as ListFragment
) displays an indeterminant progress indicator within the fragment, which is skewed off to the side. I wish to remove the indicator and use a different ProgressDialog
I implemented as the indicator instead.
Doing some research, I have discovered the function setListShownNoAnimation()
(documented here) in the ListFragment
class, but the following attempts didn't work:
onActivityCreated()
onCreate
onCreateView()
(this caused an IllegalStateException
)How can I remove the fragment's progress indicator?
The right way to do this is to call:
setListShown(true);
when you need the ProgressBar to be hidden and show the ListView. Call this when you are finished getting the data in the background and are ready to show the list.
This workaround may not be the best method to solve this, but it works nicely:
What I did was first make the Fragment not display at all when I declared it in the layout.xml file:
<fragment class="com.example.MyListFragment"
android:id="@+id/frag_list"
android:layout_width="0dp"
android:layout_height="match_parent"
android:visibility="gone" />
Then after the data has been downloaded and processed, I would then display the Fragment using a FragmentTransaction:
FragmentManager fm = getFragmentManager();
Fragment frag = fm.findFragmentById(R.id.frag_list);
FragmentTransaction ft = fm.beginTransaction();
ft.show(frag);
ft.commit();
If there is a better way to resolve this issue, I'm open to suggestions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With