AFS AFS - 13 days ago 6
Android Question

Set custom adapter for RecycleView

I have this custom adapter

package client.tclient.com.client;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;

import com.twitter.sdk.android.core.models.Tweet;
import com.twitter.sdk.android.tweetui.Timeline;
import com.twitter.sdk.android.tweetui.TweetTimelineListAdapter;


public class CustomTweetTimelineListAdapter extends TweetTimelineListAdapter {

private Context context;
/**
* Constructs a TweetTimelineListAdapter for the given Tweet Timeline.
*
* @param context the context for row views.
* @param timeline a Timeline<Tweet> providing access to Tweet data items.
* @throws IllegalArgumentException if timeline is null
*/
public CustomTweetTimelineListAdapter(Context context, Timeline<Tweet> timeline) {
super(context, timeline);
this.context = context;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);

//disable subviews
if(view instanceof ViewGroup){
disableViewAndSubViews((ViewGroup) view);
}

//enable root view and attach custom listener
view.setEnabled(true);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Long tweetId = getItemId(position);
//Toast.makeText(context, tweetId, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(context,TweetActivity.class);
intent.putExtra("TWEET_ID", tweetId);
context.startActivity(intent);
}
});
return view;
}
private void disableViewAndSubViews(ViewGroup layout) {
layout.setEnabled(false);
for (int i = 0; i < layout.getChildCount(); i++) {
View child = layout.getChildAt(i);
if (child instanceof ViewGroup) {
disableViewAndSubViews((ViewGroup) child);
} else {
child.setEnabled(false);
child.setClickable(false);
child.setLongClickable(false);
}
}
}
}


And this is the class where I use it.

public class FollowingActivity extends AppCompatActivity {

RecyclerView homeList;
SwipeRefreshLayout mySwipeRefreshLayout;
FloatingActionButton fab;

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


homeList = (RecyclerView) findViewById(R.id.homeList);
loadHomeTimeLine();
mySwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
mySwipeRefreshLayout.setOnRefreshListener(
new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
loadHomeTimeLine();
Toast.makeText(FollowingActivity.this,"Refreshing",Toast.LENGTH_LONG);
mySwipeRefreshLayout.setRefreshing(false);

}
}
);

fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Se presionĂ³ el FAB", Snackbar.LENGTH_SHORT)
.setAction("Action", null).show();
}
});
}

public void loadHomeTimeLine(){
TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient();
final StatusesService statusesService = twitterApiClient.getStatusesService();
statusesService.homeTimeline(200, 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 CustomTweetTimelineListAdapter adapter = new CustomTweetTimelineListAdapter(FollowingActivity.this,timeline);

homeList.setAdapter( adapter);//here is the problem
}

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


I cannot pass a
CustomTweetTimelineListAdapter
the
homelist.setadapter
because expects a
RecycleView.Adapter
, if I use a
ListView
instead of a
RecycleView
it works but I need a
RecycleView
to set the floating action button animation

Answer

It seems that the RecyclerView is not supported yet

More info at: https://twittercommunity.com/t/does-fabric-support-recyclerviews/62318/2