Skip to content

Instantly share code, notes, and snippets.

@carloscarucce
Created June 23, 2016 12:06
Show Gist options
  • Save carloscarucce/9457ab352e8ccf33f32d4aeb452dfa44 to your computer and use it in GitHub Desktop.
Save carloscarucce/9457ab352e8ccf33f32d4aeb452dfa44 to your computer and use it in GitHub Desktop.
class ExampleAdapter extends PagerAdapter {
private List<String> strings;
private Context context;
public ExampleAdapter(Context context){
this.context = context;
strings = new ArrayList<String>();
for(int i = 0; i < 10; i++) {
strings.add("Text " + i);
}
}
@Override
public int getCount() {
return strings.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
LinearLayout linearLayout = new LinearLayout(MainActivity.this);
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
TextView textView = new AppCompatTextView(this.context);
textView.setText(strings.get(position));
linearLayout.addView(textView);
container.addView(linearLayout);
return linearLayout;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment