Skip to content

Instantly share code, notes, and snippets.

@srcreigh
Created December 26, 2014 00:49
Show Gist options
  • Save srcreigh/4c3dab6eb802b94e2754 to your computer and use it in GitHub Desktop.
Save srcreigh/4c3dab6eb802b94e2754 to your computer and use it in GitHub Desktop.
public static final int ITEM_VIEW_TYPE_LARGE = 0;
public static final int ITEM_VIEW_TYPE_SMALL = 1;
@Override
public int getItemViewType(int position) {
if (isCategoryLarge(categories.get(position)) {
return ITEM_VIEW_TYPE_LARGE;
} else {
return ITEM_VIEW_TYPE_SMALL;
}
}
@Override
public int getViewTypeCount() {
return 2;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final int viewType = getItemViewType(position);
if (convertView == null) {
if (viewType == ITEM_VIEW_TYPE_LARGE) {
// create new large view
} else if (viewType == ITEM_VIEW_TYPE_SMALL) {
// create new small view
}
}
if (viewType == ITEM_VIEW_TYPE_LARGE) {
// set up convertView, which is guaranteed to only have been touched
// by code that knows it is large
} else if (viewType == ITEM_VIEW_TYPE_SMALL) {
// etc
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment