适用于结构上的List <tweet>的适配器

时间:2016-06-10 16:25:22

标签: android twitter twitter-fabric

我正在获取用户的主页时间轴,但是我需要一个适配器来显示推文,但我没有找到任何由ListActivity类的setListAdapter方法提供的适配器

package client.tclient.com.client;

import android.app.ListActivity;
import android.os.Bundle;

import com.twitter.sdk.android.core.Callback;
import com.twitter.sdk.android.core.Result;
import com.twitter.sdk.android.core.TwitterApiClient;
import com.twitter.sdk.android.core.TwitterCore;
import com.twitter.sdk.android.core.TwitterException;
import com.twitter.sdk.android.core.models.Tweet;
import com.twitter.sdk.android.core.services.StatusesService;
import com.twitter.sdk.android.tweetui.FixedTweetTimeline;
import com.twitter.sdk.android.tweetui.Timeline;
import com.twitter.sdk.android.tweetui.TweetTimelineListAdapter;

import java.util.List;

public class FollowingActivity extends ListActivity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_following);

        TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient();
// Can also use Twitter directly: Twitter.getApiClient()
        StatusesService statusesService = twitterApiClient.getStatusesService();

        statusesService.homeTimeline(null, null, null, null, null, null, null,
                new Callback<List<Tweet>>() {
                    @Override
                    public void success(Result<List<Tweet>> result) {

                        final FixedTweetTimeline timeline = new FixedTweetTimeline.Builder()
                                .setTweets(result.data)
                                .build();
                        final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(FollowingActivity.this)
                                .setTimeline(result.data)//this method cannot receive a List<Tweet> object like result.data
                                .build();
                        setListAdapter(adapter);
                    }

                    public void failure(TwitterException exception) {
                    }
                }
        );


    }
}

我的问题是存在List&lt;的任何适配器。鸣叫&GT;对象??

1 个答案:

答案 0 :(得分:0)

Yeap有并称为ArrayAdapter。您可以将自己的对象ArrayList作为参数传递。创建一个扩展ArrayAdapter的类,并从FollowingActivity中设置它。

实施例

public class followingAdapter extends ArrayAdapter<Tweet> {
    public followingAdapter(Context context, int resource, ArrayList<Tweet> items) {
        super(context, resource, items);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        .......
    }
}