Skip to content

Instantly share code, notes, and snippets.

@CodyEngel
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save CodyEngel/66231dfe596350223212 to your computer and use it in GitHub Desktop.

Select an option

Save CodyEngel/66231dfe596350223212 to your computer and use it in GitHub Desktop.
ListAdapter For NavigationItem in Android
public class NavigationListAdapter extends ArrayAdapter<NavigationItem> {
private Context mContext;
private ArrayList<NavigationItem> mItems;
private LayoutInflater mLayoutInflater;
public NavigationListAdapter(Context context, ArrayList<NavigationItem> items) {
super(context, 0, items);
mContext = context;
mItems = items;
mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder viewHolder;
final NavigationItem navigationItems = mItems.get(position);
if(navigationItems != null) {
if(convertView == null) {
convertView = mLayoutInflater.inflate(R.layout.list_item_navigation, null);
viewHolder = new ViewHolder();
viewHolder.tvTitle = (TextView)convertView.findViewById(R.id.tvTitle);
viewHolder.ivIcon = (ImageView)convertView.findViewById(R.id.ivIcon);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.tvTitle.setText(navigationItems.getTitle());
viewHolder.ivIcon.setImageDrawable(navigationItems.getIcon());
}
return convertView;
}
static class ViewHolder {
TextView tvTitle;
ImageView ivIcon;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment