Fabric.io usertimeline loaded event

自作多情 提交于 2019-12-11 15:03:20

问题


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?


回答1:


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.




回答2:


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);
}


来源:https://stackoverflow.com/questions/29849884/fabric-io-usertimeline-loaded-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!