0

I'm using a Twitter feed from Fabric.io,.

To set up, I'm using this method:

final UserTimeline userTimeline = new UserTimeline.Builder()
    .screenName(screenname)
    .build();
final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter(mContext, userTimeline);
listViewTweets.setAdapter(adapter);

My goal is to show a loading indicator until the feed is loaded, thus shows in the view. How do I do this?

shkschneider
  • 17,833
  • 13
  • 59
  • 112
TomCB
  • 3,983
  • 9
  • 40
  • 66
  • "thus shows in the view" what do you mean ? – Mounir Elfassi Apr 24 '15 at 14:24
  • When the feed is loaded, it is shown in the view. When it is not loaded, there is nothing. When there is nothing, I want to show the user that the feed is loading, using a loading indicator. – TomCB Apr 24 '15 at 14:26

2 Answers2

2

Before listViewTweets.setAdapter(adapter); insert:

listviewo.setEmptyView(findViewById(R.id.loading));

loading is a ProgressBar put it inside your XML where you have the ListView:

<ProgressBar
        android:id="@+id/loading"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:indeterminateDrawable="@anim/loading_rotation"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:visibility="gone" />

by this: android:indeterminateDrawable="@anim/loading_rotation" i created a picture that rotate.

to set the animation just create an xml file put it in a folder called anim :

<?xml version="1.0" encoding="utf-8"?>

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/iconloading"
android:pivotX="50%"
android:pivotY="50%" />

the loading picture isiconloading.

hope this helps.

Mounir Elfassi
  • 2,242
  • 3
  • 23
  • 38
0

You can use TweetTimelineListAdapter.registerDataSetObserver to observer adapter changes and show a loading indicator while you wait for the initial data changed event.

For example in a ListFragment:

    public void onStart() {
        ...
        final TweetTimelineListAdapter adapter = ...
        adapter.registerDataSetObserver(new DataSetObserver() {
            @Override
            public void onChanged() {    
                setListShown(true);
            }
        });
        setListAdapter(adapter);
        setListShown(false);
}
lujop
  • 13,504
  • 9
  • 62
  • 95