You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 25, 2020. It is now read-only.
I'm trying to use Spork on PagerAdapter (to display views on a ViewPager) but I'm having problems doing so. For now, I'm creating a custom view, use Spork, and then adding it to the container.
@BindLayout(R.layout.related_item_row)
public class RelatedView extends FrameLayout {
@BindView(R.id.textView_title)
TextView textViewTitle;
@BindView(R.id.imageView_play)
View imageViewPlay;
public RelatedView(Context context) {
super(context);
Spork.bind(this);
}
public void init(final RelatedFeed feed) {
textViewTitle.setText(feed.getTitle());
imageViewPlay.setVisibility(!feed.getDataType().equals("news") ? View.VISIBLE : View.GONE);
setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
}
So in the PagerAdapter I just have this:
public class RelatedPagerAdapter extends PagerAdapter {
private Activity context;
private ArrayList<RelatedFeed> items;
public RelatedPagerAdapter(Activity context, ArrayList<RelatedFeed> items) {
Spork.bind(this);
this.context = context;
this.items = items;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
final RelatedFeed feed = items.get(position);
RelatedView view = new RelatedView(context);
view.init(feed);
container.addView(view);
return view;
}
@Override
public int getCount() {
return items.size();
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((View) object);
}
}
It's working great for now. It would be great if Spork works the same way than in other views.
Another thing, how would be the approach if we didn't use PagerAdapter but instead a FragmentPagerAdapter (or FragmentStatePagerAdapter)?
The text was updated successfully, but these errors were encountered:
For RecyclerView the solution was clear because the RecyclerView.ViewHolder represents always exactly 1 View. Since this relationship is 1-on-1 and guaranteed, we can do View-binding on an object that isn't a View.
A PagerAdapter (and most other Android adapters) manage View objects directly. So creating a custom View with the bindings in it (as in the example above) seems to be the best way to go forward.
I'm trying to use Spork on PagerAdapter (to display views on a ViewPager) but I'm having problems doing so. For now, I'm creating a custom view, use Spork, and then adding it to the container.
So in the PagerAdapter I just have this:
It's working great for now. It would be great if Spork works the same way than in other views.
Another thing, how would be the approach if we didn't use PagerAdapter but instead a FragmentPagerAdapter (or FragmentStatePagerAdapter)?
The text was updated successfully, but these errors were encountered: