public FilterChannelsAdapter(Context context, YboTvDatabase database) { channels = database.selectAll(Channel.class); Set<String> favoriteIds = new HashSet<String>(); for (FavoriteChannel favoriteChannel : database.selectAll(FavoriteChannel.class)) { favoriteIds.add(favoriteChannel.getChannel()); } for (Channel channel : channels) { channel.setFavorite(favoriteIds.contains(channel.getId())); } inflater = LayoutInflater.from(context); }
@Override public View getView(int position, View convertViewIn, ViewGroup parent) { View convertView = convertViewIn; ViewHolder holder; if (convertView == null) { convertView = inflater.inflate(R.layout.filter_channel_element, null); holder = new ViewHolder(); holder.iconeChaine = (ImageView) convertView.findViewById(R.id.filter_channel_element_imageChaine); holder.displayName = (TextView) convertView.findViewById(R.id.filter_channel_element_displayName); holder.favorite = (CheckBox) convertView.findViewById(R.id.filter_channel_element_favorite); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } Channel channel = getItem(position); holder.displayName.setText(channel.getDisplayName()); holder.iconeChaine.setImageResource(channel.getIconResource()); holder.favorite.setChecked(channel.isFavorite()); return convertView; }