使用 Twitter Fabric Android Sdk 的 TweetViewAdpater 显示转发计数

Show retweet counts using Twitter Fabric Android Sdk's TweetViewAdpater

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

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

  1. ListView(如果可以的话怎么做?)

  2. 带有备用 CompactTweetView 和转推计数视图的空 LinearLayout。

如有不明之处,请询问更多信息。谢谢

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

在 fabric iu sdks 上搜索 tw__tweet_compact.xml 或 tw__tweet.xml layout.Copy 中的资源 layouts.Don 不更改名称。添加您的自定义 Texview 以显示转推计数。 这是我的习惯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>

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

 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;
    }
}

我觉得这种方式比较简单。问候