@Override public void bindView(View view, Context context, Cursor cursor) { ViewHolder vh = (ViewHolder) view.getTag(); if (vh == null || !(view instanceof XboxLiveFriendListItem)) return; XboxLiveFriendListItem friend = (XboxLiveFriendListItem) view; friend.mFriendId = cursor.getLong(0); friend.mStatusCode = cursor.getInt(COLUMN_STATUS_CODE); friend.mGamertag = cursor.getString(COLUMN_GAMERTAG); friend.mIsFavorite = (cursor.getInt(COLUMN_IS_FAVORITE) != 0); friend.mClickListener = FriendsFragment.this; vh.gamertag.setText(cursor.getString(COLUMN_GAMERTAG)); vh.currentActivity.setText(cursor.getString(COLUMN_ACTIVITY)); vh.gamerscore.setText(context.getString(R.string.x_f, cursor.getInt(COLUMN_POINTS))); String iconUrl = cursor.getString(COLUMN_ICON_URL); SoftReference<Bitmap> icon = mIconCache.get(iconUrl); if (icon != null && icon.get() != null) { // Image is in the in-memory cache vh.avatar.setImageBitmap(icon.get()); } else { // Image has likely been garbage-collected // Load it into the cache again Bitmap bmp = ImageCache.getInstance().getCachedBitmap(iconUrl); if (bmp != null) { mIconCache.put(iconUrl, new SoftReference<Bitmap>(bmp)); vh.avatar.setImageBitmap(bmp); } else { // Image failed to load - just use placeholder vh.avatar.setImageResource(R.drawable.avatar_default); } } iconUrl = cursor.getString(COLUMN_TITLE_ICON_URL); icon = mIconCache.get(iconUrl); if (icon != null && icon.get() != null) { // Image is in the in-memory cache vh.titleIcon.setImageBitmap(icon.get()); } else { // Image has likely been garbage-collected // Load it into the cache again Bitmap bmp = ImageCache.getInstance().getCachedBitmap(iconUrl); if (bmp != null) { mIconCache.put(iconUrl, new SoftReference<Bitmap>(bmp)); vh.titleIcon.setImageBitmap(bmp); } else { // Image failed to load - just use placeholder vh.titleIcon.setImageResource(R.drawable.xbox_game_empty_boxart); } } vh.isFavorite.setImageResource( friend.mIsFavorite ? R.drawable.favorite_on : R.drawable.favorite_off); }
@Override public View newView(Context context, Cursor cursor, ViewGroup parent) { LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); XboxLiveFriendListItem view = (XboxLiveFriendListItem) li.inflate(R.layout.xbl_friend_list_item, parent, false); ViewHolder vh = new ViewHolder(); view.setTag(vh); vh.gamertag = (TextView) view.findViewById(R.id.friend_gamertag); vh.currentActivity = (TextView) view.findViewById(R.id.friend_description); vh.gamerscore = (TextView) view.findViewById(R.id.friend_gp); vh.avatar = (ImageView) view.findViewById(R.id.friend_avatar_icon); vh.isFavorite = (ImageView) view.findViewById(R.id.friend_favorite); vh.titleIcon = (ImageView) view.findViewById(R.id.friend_title); return view; }