小编Adr*_*ian的帖子

XMPP与Java Asmack库支持X-FACEBOOK-PLATFORM

我正在尝试使用Smack库在Android上进行Facebook聊天.我已经从Facebook上阅读了聊天API,但我无法理解如何使用此库对Facebook进行身份验证.

任何人都可以指出我如何做到这一点?

更新:根据no.good.at.coding答案,我将此代码改编为Asmack库.一切正常,但我收到的是对登录的回复:未经授权.这是我使用的代码:

public class SASLXFacebookPlatformMechanism extends SASLMechanism
{

    private static final String NAME              = "X-FACEBOOK-PLATFORM";

    private String              apiKey            = "";
    private String              applicationSecret = "";
    private String              sessionKey        = "";

    /**
     * Constructor.
     */
    public SASLXFacebookPlatformMechanism(SASLAuthentication saslAuthentication)
    {
        super(saslAuthentication);
    }

    @Override
    protected void authenticate() throws IOException, XMPPException
    {

        getSASLAuthentication().send(new AuthMechanism(NAME, ""));
    }

    @Override
    public void authenticate(String apiKeyAndSessionKey, String host,
            String applicationSecret) throws IOException, XMPPException
    {
        if (apiKeyAndSessionKey == null || applicationSecret == null)
        {
            throw new …
Run Code Online (Sandbox Code Playgroud)

java android facebook xmpp smack

10
推荐指数
1
解决办法
1万
查看次数

LinearLayout addView无法正常工作

我遇到了LinearLayout的addView方法问题.我不知道为什么,但是如果我添加三个视图,则仅显示第一个视图.这是代码:

Comment[] comments = posts[position].getComments();
LinearLayout layout = (LinearLayout)convertView.findViewById(R.id.post_list_item_comments);
layout.removeAllViews();
for(int i=0; i<comments.length; i++) {
    View comment = inflater.inflate(R.layout.post_list_item_comment,null);
    ((TextView)comment.findViewById(R.id.post_list_item_comment_name)).setText(comments[i].getFrom().getName());
    ((TextView)comment.findViewById(R.id.post_list_item_comment_message)).setText(comments[i].getText());
    layout.addView(comment,i);
}
Run Code Online (Sandbox Code Playgroud)

我也尝试过addView(评论),但结果相同.

这是我在使用findViewById mehthod时检索的View的代码.

<LinearLayout
    android:id="@+id/post_list_item_comments"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="40dip"
    android:layout_below="@id/post_list_item_footer_text"
    android:visibility="gone"/>
Run Code Online (Sandbox Code Playgroud)

这是我膨胀的XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <View
        android:id="@+id/post_list_item_comment_divider"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@drawable/divider"
        android:layout_marginTop="2dip"
        android:layout_marginBottom="2dip"/>
    <ImageView
        android:id="@+id/post_list_item_comment_photo"
        android:layout_width="40dip"
        android:layout_height="wrap_content"
        android:layout_below="@id/post_list_item_comment_divider"
        android:adjustViewBounds="true"/>
    <TextView
        android:id="@+id/post_list_item_comment_name"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_toRightOf="@id/post_list_item_comment_photo"
        android:layout_below="@id/post_list_item_comment_divider"
        android:maxLines="2"
        android:ellipsize="end"/>
    <TextView
        android:id="@+id/post_list_item_comment_message"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_toRightOf="@id/post_list_item_comment_photo"
        android:layout_below="@id/post_list_item_comment_name"
        android:textSize="13sp"
        android:maxLines="2"
        android:ellipsize="end"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

android android-linearlayout

6
推荐指数
1
解决办法
1万
查看次数

ListView行中的ViewPager可防止触发onItemClick

我在ListView的每一行中都有一个ViewPager.它工作正常,当用户使用滑动手势时,它会更改其中的视图,但它会阻止调用ListView的onItemClick方法.我知道ViewPager是罪魁祸首,因为当我隐藏它时,会调用onItemClick,所以这就是我想要的:

我创建了一个ViewGroup作为行(RowView).此ViewGroup已onInterceptTouchEvent重写,以避免ViewPager在检测到单击时处理更多触摸事件.但仍未调用onItemClick回调.并且列表选择器不会在单击时显示.我想要这两个功能.

这是RowView的onInterceptTouchEvent的样子:

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    int actionMasked = ev.getActionMasked();
    switch(actionMasked) {
        case MotionEvent.ACTION_DOWN:
            Log.d("RowView", "OnInterceptTouchEvent - Down");
            tapDetector.onTouchEvent(ev);
            return false;
        case MotionEvent.ACTION_CANCEL:
            Log.d("RowView", "OnInterceptTouchEvent - Cancel");
            tapDetector.onTouchEvent(ev);
            break;
        case MotionEvent.ACTION_UP:
            if(tapDetector.onTouchEvent(ev)) {
                Log.d("RowView", "OnInterceptTouchEvent - UP!");
                return true;
            }
            break;
    }

    return super.onInterceptTouchEvent(ev);
}
Run Code Online (Sandbox Code Playgroud)

有什么建议可以解决吗?

编辑:关于如何在ViewPager处于活动状态时未调用MainActivity中的onItemClick的示例(Lollipop列表选择器也未出现)

主要活动

ListView listView = (ListView) findViewById(R.id.main_list);
listView.setAdapter(new MainListAdapter(this, 30));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Log.d(TAG, "onItemClick: " …
Run Code Online (Sandbox Code Playgroud)

android android-viewpager

6
推荐指数
2
解决办法
2027
查看次数

更改列表视图中行的高度

我想当用户点击一行时,该行增长以显示带有缩放动画的更多项目,但我找不到如何做到这一点.
第一:我不知道如何在运行时更改高度行.我已经尝试使项目可见,但即使我用另一个XML布局膨胀,这也不起作用.
第二:如果我实现了第一个,我想我可以制作比例动画,但任何建议都很好.

谢谢.

android listview

1
推荐指数
1
解决办法
4988
查看次数