Twitter Android SDK不执行回调

zun*_*ndi 7 java twitter android callback android-adapter

我正在使用Twitter句柄运行此代码我很确定不存在以便测试错误处理.回调中的断点永远不会被击中,无论是成功还是失败.

有关为什么会这样的指示?

就像一个注释,这个代码可以正常使用有效的Twitter句柄,但也不会调用回调.

final Callback<Tweet> actionCallback = new Callback<Tweet>() {
    @Override
    public void success(Result<Tweet> result) {
        int x = 1;
        x++; // This code is just so I can put a breakpoint here
    }
    @Override
    public void failure(TwitterException exception) {
        DialogManager.showOkDialog(context, R.string.twitter_feed_not_found);
    }
};

final UserTimeline userTimeline = new UserTimeline.Builder().screenName(handleStr + "dfdfddfdfdfasdf") // Handle that doesn't exist
        .includeReplies(false).includeRetweets(false).maxItemsPerRequest(5).build();

final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(context)
        .setTimeline(userTimeline)
        .setViewStyle(R.style.tw__TweetLightWithActionsStyle)
        .setOnActionCallback(actionCallback)
        .build();

listView.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

Cri*_*uta 3

我认为您误解了 actionCallback 的目的。从 TweetTimelineListAdapter 的源代码中,您可以看到此回调用于推文视图上的操作,例如,当您单击收藏夹图标时。我已经使用最喜欢的图标进行了测试,并且回调被调用。

看一下源码中getView方法的这个注释。

   /**
     * Returns a CompactTweetView by default. May be overridden to provide another view for the
     * Tweet item. If Tweet actions are enabled, be sure to call setOnActionCallback(actionCallback)
     * on each new subclass of BaseTweetView to ensure proper success and failure handling
     * for Tweet actions (favorite, unfavorite).
     */
Run Code Online (Sandbox Code Playgroud)

回调并不是为了处理不存在的屏幕名以及特定推文的操作/按钮。

希望这可以帮助。

更新:您不需要检测 UserTimeLine 上的任何错误,因为构建器不会抛出任何异常,并且适配器将为空,屏幕上不会显示任何行/视图。但是,如果您仍然需要检测加载中的某些“错误”,则必须依赖 UserTimeLine 的“next”方法。

看一看

  userTimeline.next(null, new Callback<TimelineResult<Tweet>>() {
        @Override
        public void success(Result<TimelineResult<Tweet>> result) {

        }

        @Override
        public void failure(TwitterException exception) {
            Log.d("TAG",exception.getMessage());
        }
    });
Run Code Online (Sandbox Code Playgroud)

此方法显示用户的下一条推文,如果调用失败回调,您将确定该用户没有任何推文或该用户不存在。