How To Customize Tweet Timeline Recycler View Adapter?



{sorry for spelling title wrong, kept getting “is it a complete sentence” error}.


So after getting a TweetTimelineRecyclerViewAdapter set on my RecyclerView and displaying a list of Tweets, I have been trying to create a custom TweetTimelineRecyclerViewAdapter so that when a user taps on a Tweet, they are not sent to a webview containing the Tweet, as is the default behavior currently. I have tried to extend TweetTimelineRecyclerViewAdapter as so:

public class MyCustomAdapter extends TweetTimelineRecyclerViewAdapter{

        public MyCustomAdapter(Context context, Timeline<Tweet> timeline) {
            super(context, timeline);

        public TweetTimelineRecyclerViewAdapter.TweetViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return super.onCreateViewHolder(parent, viewType);
           the other override methods, etc..

However the “TweetViewHolder” inside of public TweetTimelineRecyclerViewAdapter.TweetViewHolder onCreateViewHolder

immediately highlights red and throws the Error:

'' is not public in ''. Cannot be accessed from outside package

My Question is:

  1. Can the TweetTimelineRecyclerViewAdapter be extended and if so what am I doing wrong in my syntax to extend it?

  2. Is it possible in TweetTimelineRecyclerViewAdapter to change the default behavior of opening up a webview whenever
    a tweet in the list is clicked?

Any help is greatly appreciated.


Thanks for bringing this issue to our attention.

  1. It can be extended but as you pointed out it won’t help much because you cannot override the ViewHolder.
  2. We are merging in a fix and in the next release it will be possible to override the default click behavior.

P.S. I will update this post when it has been released and provide a usage example.


Twitter Kit for Android 3.1.1 has been released to jcenter and you can now override the view holder.


// Example Custom RecyclerView Adapter to override click listener
public class MyCustomRecyclerViewAdapter extends TweetTimelineRecyclerViewAdapter {

    public MyCustomRecyclerViewAdapter(Context context, Timeline<Tweet> timeline) {
        super(context, timeline);

    MyCustomRecyclerViewAdapter(Context context, Timeline<Tweet> timeline, int styleResId, Callback<Tweet> cb) {
        super(context, timeline, styleResId, cb);

    public TweetViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        Tweet tweet = new TweetBuilder().build();
        final CompactTweetView compactTweetView = new CompactTweetView(context, tweet, styleResId);
        compactTweetView.setTweetLinkClickListener(new TweetLinkClickListener() {
            public void onLinkClick(Tweet tweet, String url) {
                Log.d("TweetLinkClicked", "tweet = " + tweet.text + "url = " + url);
        return new TweetViewHolder(compactTweetView);


And invocation:

final MyCustomRecyclerViewAdapter adapter = new MyCustomRecyclerViewAdapter(getActivity(), userTimeline,, actionCallback);


Gettng Tweet ID from Timeline? (AndroidTwitterKit)

Thanks Adam.

Just a heads up to anyone using the example above, make sure you use "parent.getContext()"
final CompactTweetView compactTweetView = new CompactTweetView(context, tweet, styleResId);
like so
final CompactTweetView compactTweetView = new CompactTweetView(parent.getContext(),tweet,styleResId);
in order to avoid any crashes when a tweet gets clicked.

Also just like specified in this thread here the setTweetLinkClickListener is only for links (Twitter handles and http links) inside of Tweets that are clicked. In order
to override the body of the Tweet you must override setOnTouchListener like so

compactTweetView.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                Toast.makeText(parent.getContext(),"you clicked the body",Toast.LENGTH_LONG).show();
                return true;