是否存在类似Facebook的视图回调?

时间:2017-03-12 16:35:04

标签: android facebook callback

我正在尝试在Android上实现类似Facebook的视图,但是当用户点击它时会有一些回调和通知。我已经尝试了一切并谷歌分配,找不到任何有用的东西。当我尝试将View.OnClickListener添加到类似视图时,它不会触发。到目前为止,我有这段代码:

    likeView.setObjectIdAndType(
         "https://www.facebook.com/SomePage",
         LikeView.ObjectType.PAGE);
    likeView.setLikeViewStyle(LikeView.Style.BUTTON);
            likeView.setAuxiliaryViewPosition(LikeView.AuxiliaryViewPosition.INLINE);
likeView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // TO DO
                }
    });

这甚至可能吗?我只是想知道什么时候像facebook一样按下了facebook。感谢您的回答和帮助。

1 个答案:

答案 0 :(得分:1)

我找到了一个黑客。在LikeView中识别内部LikeButton很重要。比你可以处理onTouch事件。这对我来说已经足够了(需要点击登录按钮)。

LikeView likeView = (LikeView) widgetView.findViewById(R.id.button_fcb);
    likeView.setObjectIdAndType(
            "<< page id >>",
            LikeView.ObjectType.PAGE);
    LikeButton likeButton = findLikeButton(likeView);
    if (likeButton != null) {
        likeButton.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                ... do anything ...
                return false;
            }
        });
    }    

private LikeButton findLikeButton(ViewGroup viewGroup) {
    for (int i = 0; i < viewGroup.getChildCount(); i++) {
        View childView = viewGroup.getChildAt(i);
        if (childView instanceof LikeButton) {
            return (LikeButton)childView;
        }
        if (childView instanceof ViewGroup) {
            return findLikeButton((ViewGroup)childView);
        }
    }
    return null;
}