使用Twitter Fabric Android Sdk的TweetViewAdpater显示转推计数 [英] Show retweet counts using Twitter Fabric Android Sdk's TweetViewAdpater

查看:64
本文介绍了使用Twitter Fabric Android Sdk的TweetViewAdpater显示转推计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Twitter的android sdk开发应用程序.在给定的SDK中,有一个用于显示Tweets的 CompactTweetView ,但是其中没有用于显示转发数的字段.要显示我正在使用sdk中提供的 TweetViewAdapter 的推文.

I am using Twitter's android sdk for developing an app. In the given sdk there is a CompactTweetView for displaying the Tweets, but there is no field for showing retweets counts in it. To display the tweets I am using TweetViewAdapter provided in sdk.

现在我想在每条推文下方显示转发数.我如何实现我的目标?我是否必须在ListView中的每个条目之后添加单独的行以显示转推计数,或者是否可以通过其他任何方式扩展CompactTweetView以包括转推计数.另一种方法是,我使用一个空的LinearLayout并在每个CompactTweetView之后添加一个行用于转发计数视图.两种情况下的性能如何

Now I want to show the retweet counts also below each tweets. How can I achieve my objective ? Do I have to add separate rows after each entry in ListView to show retweet counts or is there any other way by which I can extend the CompactTweetView to include retweet count. Another way is that I use an empty LinearLayout and add a row for retweet count view after each CompactTweetView. What will be the performance in both cases

  1. ListView(如果可能的话,该怎么做?)

  1. ListView (If possible then how to do it ?)

带有备用CompactTweetView和Reweet计数视图的空LinearLayout.

Empty LinearLayout with alternate CompactTweetView and retweet count View.

如果不清楚,请询问更多信息.谢谢.

If anything is not clear please ask for more information. Thanks.

使用带有TweetViewAdapter的ListView的我的Twitter应用程序的当前状态. 我想在每行之后显示转发数.

Current state of of my twitter app using ListView with TweetViewAdapter. I want to display retweet count after each row.

推荐答案

在结构iu sdks上搜索tw__tweet_compact.xml或tw__tweet.xml布局.在资源布局中复制.请勿更改名称.添加您的自定义Texview以显示转发数. 这是我的自定义tw__tweet_compact.xml

Search on fabric iu sdks the tw__tweet_compact.xml or tw__tweet.xml layout.Copy in resources layouts.Don't change the name. Add your custom Texview to show retweets count. This is my custom tw__tweet_compact.xml

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tw__tweet_view"
style="@style/tw__CompactTweetContainer">

<TextView
    android:id="@+id/tw__tweet_retweeted_by"
    style="@style/tw__TweetRetweetedBy.Compact"
    android:layout_alignLeft="@+id/tw__author_attribution"
    tools:text="retweeted by" />

<ImageView
    android:id="@+id/tw__tweet_author_avatar"
    style="@style/tw__TweetAvatar.Compact"
    android:layout_below="@id/tw__tweet_retweeted_by"
    tools:background="@color/tw__tweet_media_preview_bg_color"
    tools:ignore="ContentDescription" />

<!--Name and timestamp don't ellipsize, but @username in the middle does ellipsize-->
<LinearLayout
    android:id="@+id/tw__author_attribution"
    style="@style/tw__CompactAttributionLine"
    android:layout_below="@id/tw__tweet_retweeted_by"
    android:layout_toEndOf="@id/tw__tweet_author_avatar"
    android:layout_toRightOf="@id/tw__tweet_author_avatar">

    <TextView
        android:id="@+id/tw__tweet_author_full_name"
        style="@style/tw__TweetFullName.Compact"
        tools:text="Jack" />

    <TextView
        android:id="@+id/tw__tweet_author_screen_name"
        style="@style/tw__TweetScreenName.Compact"
        tools:text="@jack" />

    <TextView
        android:id="@+id/tw__tweet_timestamp"
        style="@style/tw__TweetTimestamp.Compact"
        tools:text="• 03/21/2006" />

</LinearLayout>

<ImageView
    android:id="@+id/tw__twitter_logo"
    style="@style/tw__TwitterLogo.Compact"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_below="@id/tw__tweet_retweeted_by"
    tools:ignore="ContentDescription" />

<com.twitter.sdk.android.tweetui.internal.util.AspectRatioImageView
    android:id="@+id/tw__tweet_media"
    style="@style/tw__TweetMedia.Compact"
    android:layout_below="@id/tw__author_attribution"
    android:layout_toEndOf="@id/tw__tweet_author_avatar"
    android:layout_toRightOf="@id/tw__tweet_author_avatar"
    tools:ignore="ContentDescription" />

<TextView
    android:id="@+id/tw__tweet_text"
    style="@style/tw__TweetText.Compact"
    android:layout_below="@id/tw__tweet_media"
    android:layout_toEndOf="@id/tw__tweet_author_avatar"
    android:layout_toRightOf="@id/tw__tweet_author_avatar"
    tools:text="just setting up my twttr" />

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rtwfavLayout"
    android:layout_width="match_parent"
    android:layout_height="36dp"
    android:layout_below="@+id/tw__tweet_text"
    android:layout_toEndOf="@+id/tw__tweet_author_avatar"
    android:layout_toRightOf="@+id/tw__tweet_author_avatar"
    android:orientation="horizontal">

    <ImageView
        android:layout_width="15dp"
        android:layout_height="15dp"
        android:layout_marginBottom="2dp"
        android:layout_marginRight="2dp"
        android:layout_marginTop="11dp"
        android:scaleType="fitCenter"
        android:src="@drawable/tw__ic_retweet_light" />

    <TextView
        android:id="@+id/rtwtxt"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="2dp"
        android:layout_marginTop="11dp"
        android:singleLine="true"


        />

    <ImageView
        android:layout_width="15dp"
        android:layout_height="15dp"
        android:layout_marginBottom="2dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="2dp"
        android:layout_marginTop="11dp"
        android:scaleType="fitCenter"
        android:src="@drawable/favourite" />

    <TextView
        android:id="@+id/favtxt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="2dp"
        android:layout_marginTop="11dp"
        android:drawablePadding="5dp"
        android:singleLine="true" />

</LinearLayout>

</RelativeLayout>

在修改您的tweet适配器之后.在方法getView中,添加TextView并设置TextView中的转发数.收藏夹的数量效果不佳.仅显示自己喜欢的推文.其他用户的收藏夹不会显示.

After modifying your tweet adapter. In the method getView add TextView and set the number of retweets in the TextView. The number of favorites does not work well. Only shows own favorite tweets. Favorite tweets of other users don't displays.

 public class TweetAdapter extends TweetTimelineListAdapter {
    public TweetAdapter(Context context, Timeline<Tweet> timeline) {
        super(context, timeline);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final View view = super.getView(position, convertView, parent);
        CompactTweetView compactTweetView = (CompactTweetView) view;

        TextView txtfav = (TextView) compactTweetView.findViewById(R.id.favtxt);

    TextView txtrtw = (TextView) compactTweetView.findViewById(R.id.rtwtxt);


    if (compactTweetView.getTweet().retweetedStatus != null) {
        txtfav.setText(String.valueOf(compactTweetView.getTweet().retweetedStatus.favoriteCount));
        if (txtfav.getText().equals("null")) {
            txtfav.setText(String.valueOf(compactTweetView.getTweet().favoriteCount));
        }
        txtrtw.setText(String.valueOf(compactTweetView.getTweet().retweetedStatus.retweetedStatus));
        if (txtrtw.getText().equals("null")) {
            txtrtw.setText(String.valueOf(compactTweetView.getTweet().retweetCount));
        }
    } else {
        txtfav.setText(String.valueOf(compactTweetView.getTweet().favoriteCount));
        txtrtw.setText(String.valueOf(compactTweetView.getTweet().retweetCount));
    }

        return compactTweetView;
    }
}

我认为这种方式比较容易.问候

I think this way is easier. Regards

这篇关于使用Twitter Fabric Android Sdk的TweetViewAdpater显示转推计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆