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

I created a mapping using Fragments , which populates data pulled from the Internet. Although the code itself works as expected without any problems, one of the fragments (implemented as a ListFragment ) displays an undefined progress indicator inside the fragment, which is skewed to the side. I want to remove the indicator and use another ProgressDialog option instead.

After doing some research, I found the setListShownNoAnimation() function (registered here ) in the ListFragment class, but the following attempts didn Work:

  • Call setListShownNoAnimation () on the onActivityCreated()
  • Calling it in onCreate Parent Activity
  • Calling it in the onCreateView() fragment (this caused an IllegalStateException )

How to remove a progress indicator of a fragment?

+8
android android-fragments
source share
3 answers

The right way to do this is to call:

 setListShown(true); 

when you need the ProgressBar to be hidden and show ListView. Call it when you finish receiving data in the background and are ready to show the list.

+24
source share

This workaround may not be the best method to solve this problem, but it works just fine:

What I did was to 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 loaded and processed, I would then display the Fragment using 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 solve this problem, I am open to suggestions.

+1
source share
 @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { adapter.swapCursor(cursor); if(isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } } 

But you have to setListShown(false) , where you set the ListAdapter . It works great.

+1
source share

All Articles