簡體   English   中英

使用Twitter Fabric Android Sdk的TweetViewAdpater顯示轉推計數

[英]Show retweet counts using Twitter Fabric Android Sdk's TweetViewAdpater

我使用Twitter的android sdk開發應用程序。 在給定的sdk中有一個用於顯示推文的CompactTweetView ,但是沒有用於顯示轉推計數的字段。 要顯示推文我正在使用sdk中提供的TweetViewAdapter

現在我想在每條推文下面顯示轉推計數。 我怎樣才能實現目標? 我是否必須在ListView中的每個條目之后添加單獨的行以顯示轉發計數,或者是否有任何其他方式可以擴展CompactTweetView以包括轉推計數。 另一種方法是我使用一個空的LinearLayout並在每個CompactTweetView之后為轉推計數視圖添加一行。 兩種情況下的表現如何?

  1. ListView(如果可能的話怎么做?)

  2. 使用備用CompactTweetView和轉推計數視圖清空LinearLayout。

如果有任何不清楚的地方,請詢問更多信息。 謝謝。

使用帶有TweetViewAdapter的ListView的我的Twitter應用程序的當前狀態。 我想在每一行后顯示轉推計數。 在此輸入圖像描述

搜索結構iu sdks tw__tweet_compact.xml或tw__tweet.xml layout.Copy在資源布局中。不要更改名稱。 添加自定義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;
    }
}

我認為這種方式更容易。 問候

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM