Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding the "Loading..." indicator when implementing a ListFragment

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:

  • Calling setListShownNoAnimation() in the fragment's onActivityCreated()
  • Calling it in the parent activity's onCreate
  • Calling it in the fragment's onCreateView() (this caused an IllegalStateException)

How can I remove the fragment's progress indicator?

like image 527
seeming.amusing Avatar asked Feb 13 '12 08:02

seeming.amusing


2 Answers

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.

like image 119
Srichand Yella Avatar answered Nov 11 '22 12:11

Srichand Yella


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.

like image 26
seeming.amusing Avatar answered Nov 11 '22 12:11

seeming.amusing