编程语言
首页 > 编程语言> > java – 在Android应用程序中使用Fabric Twitter Kit加载用户时间线时无法设置回调

java – 在Android应用程序中使用Fabric Twitter Kit加载用户时间线时无法设置回调

作者:互联网

我正在使用Fabric Twitter Kit来加载用户时间表.但是,我无法使回调正常工作.我按照官方的例子,但仍然没有调用我的成功和失败方法.

这是我的完整代码:

public class TwitterFragment extends ListFragment {


    final Callback<Tweet> callback = new Callback<Tweet>() {
        @Override
        public void success(Result<Tweet> result) {
            setListShown(true);
            Toast.makeText(getActivity(), "NotFail", Toast.LENGTH_LONG).show();
        }

        @Override
        public void failure(TwitterException e) {
            Toast.makeText(getActivity(), "Fail", Toast.LENGTH_LONG).show();
        }
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        startWork();

    }

    public void startWork() {

        final UserTimeline userTimeline = new UserTimeline.Builder().screenName(Config.TWITTER_ACCOUNT).build();
        final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(getActivity())
                .setOnActionCallback(callback).setTimeline(userTimeline).setViewStyle(R.style.tw__TweetDarkStyle).build();
        setListAdapter(adapter);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.twitter_layout, container, false);
    }

}

任何想法如何使一切工作?

解决方法:

结束了搞清楚.

Callback的类型需要是`TimelineResult.您的代码应如下所示:

final Callback<TimelineResult<Tweet>> callback = new Callback<TimelineResult<Tweet>>() {

        @Override
        public void success(Result<TimelineResult<Tweet>> result) {
            Log.d("TAG", "success");
            progressDialog.dismiss();
        }

        @Override
        public void failure(TwitterException e) {
            Log.d("TAG", "Failure");
            progressDialog.dismiss();
            Toast.makeText(getActivity(), "Error", Toast.LENGTH_LONG).show();
        }
    };

    adapter = new TweetTimelineListAdapter.Builder(getActivity()).setTimeline(userTimeline).build();
    userTimeline.next(null, callback);

标签:java,android,twitter,twitter-fabric
来源: https://codeday.me/bug/20190706/1399149.html