Customize a TweetTimeline

android
embeddedtimeline

#1

Hi all!

I need to customize a TweetTimeline by adding an identification number at the left part of each tweet, something like the following image:

Before creating my own Adapter and trying to read each Tweet from List<Tweet>, I want to know if I can edit somehow the TweetTimelineListAdapter in order to change the layout of each element. Is this possible?

The code that I am using for obtaining the List<Tweet> object is the following:

TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient();
        StatusesService statusesService = twitterApiClient.getStatusesService();

        Call<List<Tweet>> call = statusesService.homeTimeline(200,null,null,false,false,true,true);
        call.enqueue(new Callback<List<Tweet>>() {
            @Override
            public void success(Result<List<Tweet>> result) {
                ListView listView = (ListView) findViewById(R.id.home_list);
                final FixedTweetTimeline timeline = new FixedTweetTimeline.Builder()
                        .setTweets(result.data)
                        .build();
                final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(HomeTimelineActivity.this)
                        .setTimeline(timeline)
                        .build();
                listView.setAdapter(adapter);
            }

            @Override
            public void failure(TwitterException exception) {
                Toast.makeText(HomeTimelineActivity.this,exception.toString(),Toast.LENGTH_SHORT).show();
            }
        });

#2

You could override TweetTimelineListAdapter#getView(int position, View convertView, ViewGroup parent) to return your custom view.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View tweetView = super.getView(position, convertView, parent);
    
   // Add view to another layout and return the view.
}

#3

Thanks for the answer!

But how can I access to each element layout from the View in order to edit it?


#4

We don’t provide access to the internal of the Tweet view. But you should be able to add numbers without access to internal views.


#6

This isn’t working for me. I wanted to wrap each tweet in a CardLayout.

First I extended CompactTweetView as MyCompactTweetView to override getLayout and return a custom layout id. I copied the original compact tweet layout and placed it inside a card view.

Then I extended TweetTimelineListAdapter as MyTweetTimelineListAdapter and override getView to call MyCompactTweetView.

However, the build() function of the extended MyTweetTimelineListAdapter.Builder() only returns a TweetTimelineListAdapter object which forces the code to run getView from TweetTimelineListAdapter. So my overridden getView is never touched.


#7

Try using the constructor of your MyTweetTimelineListAdapter instead of the builder pattern,
e.g., MyTweetTimelineListAdapter adapter = new MyTweetTimelineListAdapter(getActivity(), timeline);