@Override public View newView(Context context, Cursor cursor, ViewGroup parent) { View view = mInflater.inflate(R.layout.comments_2_me, null); ViewHolder holder = new ViewHolder(); holder.myText = (TweetTextView) view.findViewById(R.id.my_text); holder.myTextCreateAt = (TextView) view.findViewById(R.id.my_create_at); holder.myTextCreateAtIndex = cursor.getColumnIndex(Comment.created_at); holder.avatar = (ImageView) view.findViewById(R.id.avatar); holder.screenName = (TextView) view.findViewById(R.id.screen_name); holder.screenNameIndex = cursor.getColumnIndex(User.screen_name); holder.remarkIndex = cursor.getColumnIndex(User.remark); holder.hisText = (TweetTextView) view.findViewById(R.id.his_text); holder.uidIndex = cursor.getColumnIndex(Comment.uid); holder.hisCreateAt = (TextView) view.findViewById(R.id.his_create_at); holder.hisCreateAtIndex = cursor.getColumnIndex(Comment.created_at); holder.avatarIndex = cursor.getColumnIndex(User.avatar_large); holder.hisTextIndex = cursor.getColumnIndex(Comment.columnText); holder.statusIndex = cursor.getColumnIndex(Comment.status); holder.replyCommentIndex = cursor.getColumnIndex(Comment.reply_comment); view.setTag(holder); return view; }
@Override public View getView(final int position, View convertView, ViewGroup arg2) { ViewHolder holder = null; if (convertView == null) { convertView = this.layoutInflater.inflate(R.layout.favourite_item, null); holder = new ViewHolder(); holder.avatar = (ImageView) convertView.findViewById(R.id.phone_avatar); convertView.setTag(holder); } else holder = (ViewHolder) convertView.getTag(); final FavouriteItem favouriteItem = mFavouriteItems.get(position); Uri photoUri = null; if (StringUtility.isEmpty(favouriteItem.phoneNo)) { holder.avatar.setImageResource(R.drawable.ic_contact_picture_holo_light); } else photoUri = Utils.getPhotoUriFromPhoneNumber(mContext.getContentResolver(), favouriteItem.phoneNo); if (photoUri != null) { holder.avatar.setImageURI(photoUri); } else { holder.avatar.setImageResource(R.drawable.ic_contact_picture_holo_light); } holder.avatar.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { String phone = favouriteItem.phoneNo; Intent intent = new Intent(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:" + phone)); mContext.startActivity(intent); } }); return convertView; }
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = layoutInflater.inflate(res, null); holder.avatar = (ImageView) convertView.findViewById(R.id.avatar); holder.unreadMsgView = (TextView) convertView.findViewById(R.id.unread_msg_number); holder.nameTextview = (TextView) convertView.findViewById(R.id.name); holder.tvHeader = (TextView) convertView.findViewById(R.id.header); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } User user = getItem(position); if (user == null) Log.d("ContactAdapter", position + ""); // 设置nick,demo里不涉及到完整user,用username代替nick显示 String username = user.getUsername(); String header = user.getHeader(); if (position == 0 || header != null && !header.equals(getItem(position - 1).getHeader())) { if ("".equals(header)) { holder.tvHeader.setVisibility(View.GONE); } else { holder.tvHeader.setVisibility(View.VISIBLE); holder.tvHeader.setText(header); } } else { holder.tvHeader.setVisibility(View.GONE); } // 显示申请与通知item if (username.equals(Constant.NEW_FRIENDS_USERNAME)) { holder.nameTextview.setText(user.getNick()); holder.avatar.setImageResource(R.drawable.new_friends_icon); if (user.getUnreadMsgCount() > 0) { holder.unreadMsgView.setVisibility(View.VISIBLE); holder.unreadMsgView.setText(user.getUnreadMsgCount() + ""); } else { holder.unreadMsgView.setVisibility(View.INVISIBLE); } } else if (username.equals(Constant.GROUP_USERNAME)) { // 群聊item holder.nameTextview.setText(user.getNick()); holder.avatar.setImageResource(R.drawable.groups_icon); } else { holder.nameTextview.setText(username); // 设置用户头像 UserUtils.setUserAvatar(username, holder.avatar); if (holder.unreadMsgView != null) holder.unreadMsgView.setVisibility(View.INVISIBLE); } return convertView; }
@Override public View newView(Context context, Cursor cursor, ViewGroup parent) { View view = LayoutInflater.from(context).inflate(R.layout.user_row, null); ViewHolder holder = new ViewHolder(); holder.avatar = (ImageView) view.findViewById(R.id.avatar); holder.avatarIndex = cursor.getColumnIndex(AVATAR); holder.nick = (TextView) view.findViewById(R.id.nick); holder.nickIndex = cursor.getColumnIndex(NICK); holder.status = (TextView) view.findViewById(R.id.status); holder.statusIndex = cursor.getColumnIndex(STATUS); view.setTag(holder); return view; }
@Override public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder viewHolder; if (convertView == null) { convertView = inflater.inflate(R.layout.item_list_block_user, null); viewHolder = new ViewHolder(); viewHolder.avatar = (ImageView) convertView.findViewById(R.id.avatar); viewHolder.userName = (TextView) convertView.findViewById(R.id.tv_username); viewHolder.unblock = (Button) convertView.findViewById(R.id.btn_unblock); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } viewHolder = (ViewHolder) convertView.getTag(); ListBlockUserModel listBlockUserModel = listBlockUser.get(position); if (listBlockUserModel.getUserName() != null && !listBlockUserModel.getUserName().equals("")) { viewHolder.userName.setText(listBlockUserModel.getUserName()); } if (listBlockUserModel.getAvatar() != null && !listBlockUserModel.getAvatar().equals("")) { ImageLoader.getInstance() .displayImage(listBlockUserModel.getAvatar(), viewHolder.avatar, defaultOptions); } viewHolder.unblock.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { MyYesNoImp myYesNoImp = new MyYesNoImp() { @Override public void onNegative() {} @Override public void onPositive() { ((ListBlockUserActivity) context).unblock(position); } }; MyYesNoDialog.showDialog("Do you want to unblock this user?", context, myYesNoImp); } }); return convertView; }
@Override public View getView(int position, View convertView, ViewGroup parent) { View rowView = convertView; ViewHolder viewHolder = null; if (rowView == null) { LayoutInflater inflate = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); rowView = inflate.inflate(R.layout.row_dashboard_alert, null); viewHolder = new ViewHolder(); viewHolder.avatar = (ImageView) rowView.findViewById(R.id.avatar); viewHolder.name = (TextView) rowView.findViewById(R.id.name); viewHolder.alert = (TextView) rowView.findViewById(R.id.alert); viewHolder.time = (RelativeTimeTextView) rowView.findViewById(R.id.time); viewHolder.icon = (ImageView) rowView.findViewById(R.id.icon); viewHolder.arrow = (ImageView) rowView.findViewById(R.id.arrow); rowView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } DashboardGiftItem item = mlst.get(position); if (item.getPhoto().length() > 0) { Picasso.with(mContext) .load(item.getPhoto()) .placeholder(R.drawable.avatar) .into(viewHolder.avatar); } else { viewHolder.avatar.setImageResource(R.drawable.avatar); } viewHolder.name.setText(item.getUsernameSend().toString()); viewHolder.alert.setText("Sent you a gift"); viewHolder.time.setReferenceTime(item.getTime()); viewHolder.icon.setImageResource(R.drawable.ic_gift); viewHolder.arrow.setImageResource(R.drawable.arrow_right); if (item.getStatus() == 0) { rowView.setBackgroundColor(Color.parseColor("#e3f4f8")); viewHolder.icon.setImageResource(R.drawable.gift_icon); viewHolder.name.setTextColor(Color.parseColor("#101010")); viewHolder.name.setTypeface(null, Typeface.BOLD); viewHolder.alert.setTypeface(null, Typeface.BOLD); } return rowView; }
@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; }
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { convertView = inflater.inflate(R.layout.recent_item, null); holder = new ViewHolder(); holder.userName = (TextView) convertView.findViewById(R.id.recent_name); holder.sendTime = (TextView) convertView.findViewById(R.id.recent_time); holder.message = (TextView) convertView.findViewById(R.id.recent_msg); holder.unread_num = (TextView) convertView.findViewById(R.id.recent_unread_num); holder.avatar = (ImageView) convertView.findViewById(R.id.img_avatar); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } final RecentEntity entity = listRecentMsg.get(position); holder.userName.setText( (entity.getNick() != null && !entity.getNick().trim().equals("")) ? entity.getNick() : entity.getName()); holder.sendTime.setText(DateHelper.GetStringFormat(entity.getMessage().timestamp())); holder.message.setText(getMsgContent(entity.getMessage())); if (entity.getCount() > 0) { holder.unread_num.setVisibility(View.VISIBLE); if (entity.getCount() > 99) { holder.unread_num.setText("99+"); } else { holder.unread_num.setText(entity.getCount() + ""); } holder.unread_num.setTextColor(Color.BLACK); } else { holder.unread_num.setVisibility(View.INVISIBLE); } if (entity.getIsGroupMsg()) { holder.avatar.setImageResource(R.drawable.icon_group); } else { holder.avatar.setImageResource(R.drawable.chat_default_avatar); } return convertView; }
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder viewHolder; if (convertView == null) { // inflate the layout LayoutInflater inflater = LayoutInflater.from(getContext()); convertView = inflater.inflate(layoutResourceId, parent, false); // well set up the ViewHolder viewHolder = new ViewHolder(); viewHolder.title = (TextView) convertView.findViewById(R.id.title); viewHolder.subtitle = (TextView) convertView.findViewById(R.id.subtitle); viewHolder.info = (TextView) convertView.findViewById(R.id.info); viewHolder.avatar = (ImageView) convertView.findViewById(R.id.imageView); // store the holder with the view. convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } viewHolder.position = position; Matter matter = getItem(position); if (matter != null && viewHolder != null) { setTitle(viewHolder.title, matter); setSubtitle(viewHolder.subtitle, matter); setInfo(viewHolder.info, matter); setImage(viewHolder, matter, position); } return convertView; }
@Override public View getView(final Context context, LayoutInflater inflater, View convertView) { ViewHolder holder; if (convertView == null) { convertView = inflater.inflate(R.layout.list_item_contributor, null); holder = new ViewHolder(); holder.username = (TextView) convertView.findViewById(R.id.username); holder.contributionCount = (TextView) convertView.findViewById(R.id.contribution_count); holder.avatar = (ImageView) convertView.findViewById(R.id.avatar); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.username.setText(username); holder.contributionCount.setText( context .getResources() .getQuantityString(R.plurals.contribution_count, contributionCount, contributionCount)); Picasso.with(context).load(avatarUrl).into(holder.avatar); return convertView; }
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = inflater.inflate(R.layout.row_chat_history, parent, false); } ViewHolder holder = (ViewHolder) convertView.getTag(); if (holder == null) { holder = new ViewHolder(); holder.name = (TextView) convertView.findViewById(R.id.name); holder.unreadLabel = (TextView) convertView.findViewById(R.id.unread_msg_number); holder.message = (TextView) convertView.findViewById(R.id.message); holder.time = (TextView) convertView.findViewById(R.id.time); holder.avatar = (ImageView) convertView.findViewById(R.id.avatar); holder.msgState = convertView.findViewById(R.id.msg_state); holder.list_item_layout = (RelativeLayout) convertView.findViewById(R.id.list_item_layout); convertView.setTag(holder); } if (position % 2 == 0) { holder.list_item_layout.setBackgroundResource(R.drawable.mm_listitem); } else { holder.list_item_layout.setBackgroundResource(R.drawable.mm_listitem_grey); } // 获取与此用户/群组的会话 EMConversation conversation = getItem(position); // 获取用户username或者群组groupid String username = conversation.getUserName(); if (conversation.getType() == EMConversationType.GroupChat) { // 群聊消息,显示群聊头像 holder.avatar.setImageResource(R.drawable.group_icon); EMGroup group = EMGroupManager.getInstance().getGroup(username); holder.name.setText(group != null ? group.getGroupName() : username); } else if (conversation.getType() == EMConversationType.ChatRoom) { holder.avatar.setImageResource(R.drawable.group_icon); EMChatRoom room = EMChatManager.getInstance().getChatRoom(username); holder.name.setText( room != null && !TextUtils.isEmpty(room.getName()) ? room.getName() : username); } else { UserUtils.setUserAvatar(getContext(), username, holder.avatar); if (username.equals(Constant.GROUP_USERNAME)) { holder.name.setText("群聊"); } else if (username.equals(Constant.NEW_FRIENDS_USERNAME)) { holder.name.setText("申请与通知"); } Map<String, RobotUser> robotMap = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getRobotList(); if (robotMap != null && robotMap.containsKey(username)) { String nick = robotMap.get(username).getNick(); if (!TextUtils.isEmpty(nick)) { holder.name.setText(nick); } else { holder.name.setText(username); } } else { UserUtils.setUserNick(username, holder.name); } } if (conversation.getUnreadMsgCount() > 0) { // 显示与此用户的消息未读数 holder.unreadLabel.setText(String.valueOf(conversation.getUnreadMsgCount())); holder.unreadLabel.setVisibility(View.VISIBLE); } else { holder.unreadLabel.setVisibility(View.INVISIBLE); } if (conversation.getMsgCount() != 0) { // 把最后一条消息的内容作为item的message内容 EMMessage lastMessage = conversation.getLastMessage(); holder.message.setText( SmileUtils.getSmiledText( getContext(), getMessageDigest(lastMessage, (this.getContext()))), BufferType.SPANNABLE); holder.time.setText(DateUtils.getTimestampString(new Date(lastMessage.getMsgTime()))); if (lastMessage.direct == EMMessage.Direct.SEND && lastMessage.status == EMMessage.Status.FAIL) { holder.msgState.setVisibility(View.VISIBLE); } else { holder.msgState.setVisibility(View.GONE); } } return convertView; }
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.ease_row_chat_history, parent, false); } ViewHolder holder = (ViewHolder) convertView.getTag(); if (holder == null) { holder = new ViewHolder(); holder.name = (TextView) convertView.findViewById(R.id.name); holder.unreadLabel = (TextView) convertView.findViewById(R.id.unread_msg_number); holder.message = (TextView) convertView.findViewById(R.id.message); holder.time = (TextView) convertView.findViewById(R.id.time); holder.avatar = (ImageView) convertView.findViewById(R.id.avatar); holder.msgState = convertView.findViewById(R.id.msg_state); holder.list_itease_layout = (RelativeLayout) convertView.findViewById(R.id.list_itease_layout); convertView.setTag(holder); } holder.list_itease_layout.setBackgroundResource(R.drawable.ease_mm_listitem); // 获取与此用户/群组的会话 EMConversation conversation = getItem(position); // 获取用户username或者群组groupid String username = conversation.getUserName(); if (conversation.getType() == EMConversationType.GroupChat) { // 群聊消息,显示群聊头像 holder.avatar.setImageResource(R.drawable.ease_group_icon); EMGroup group = EMClient.getInstance().groupManager().getGroup(username); holder.name.setText(group != null ? group.getGroupName() : username); } else if (conversation.getType() == EMConversationType.ChatRoom) { holder.avatar.setImageResource(R.drawable.ease_group_icon); EMChatRoom room = EMClient.getInstance().chatroomManager().getChatRoom(username); holder.name.setText( room != null && !TextUtils.isEmpty(room.getName()) ? room.getName() : username); } else { EaseUserUtils.setUserAvatar(getContext(), username, holder.avatar); EaseUserUtils.setUserNick(username, holder.name); } if (conversation.getUnreadMsgCount() > 0) { // 显示与此用户的消息未读数 holder.unreadLabel.setText(String.valueOf(conversation.getUnreadMsgCount())); holder.unreadLabel.setVisibility(View.VISIBLE); } else { holder.unreadLabel.setVisibility(View.INVISIBLE); } if (conversation.getAllMsgCount() != 0) { // 把最后一条消息的内容作为item的message内容 EMMessage lastMessage = conversation.getLastMessage(); holder.message.setText( EaseSmileUtils.getSmiledText( getContext(), EaseCommonUtils.getMessageDigest(lastMessage, (this.getContext()))), BufferType.SPANNABLE); holder.time.setText(DateUtils.getTimestampString(new Date(lastMessage.getMsgTime()))); if (lastMessage.direct() == EMMessage.Direct.SEND && lastMessage.status() == EMMessage.Status.FAIL) { holder.msgState.setVisibility(View.VISIBLE); } else { holder.msgState.setVisibility(View.GONE); } } // 设置自定义属性 holder.name.setTextColor(primaryColor); holder.message.setTextColor(secondaryColor); holder.time.setTextColor(timeColor); if (primarySize != 0) holder.name.setTextSize(TypedValue.COMPLEX_UNIT_PX, primarySize); if (secondarySize != 0) holder.message.setTextSize(TypedValue.COMPLEX_UNIT_PX, secondarySize); if (timeSize != 0) holder.time.setTextSize(TypedValue.COMPLEX_UNIT_PX, timeSize); return convertView; }
@Override public View getView(int position, View convertView, ViewGroup parent) { Status mStatus = mData.get(position); User user = mStatus.getUser(); Status retweetedStatus = null; if (mStatus.getRetweetedStatus() != null) { retweetedStatus = mStatus.getRetweetedStatus(); } String avatar_url = user.getProfileImageUrl(); String name = user.getName(); String text = mStatus.getText(); String image_url = mStatus.getThumbnailPic(); String source = mStatus.getSource().getName(); Boolean verified = user.isVerified(); int statuses_count = mStatus.getCommentsCount(); int followers_count = mStatus.getRepostsCount(); String created_at = TimeUtil.converTime(new Date(mStatus.getCreatedAt()).getTime() / 1000); if (convertView == null) { holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.weibo_listview_item, null); holder.name = (TextView) convertView.findViewById(R.id.item_screen_name); holder.avatar = (ImageView) convertView.findViewById(R.id.item_profile_image); holder.text = (TextView) convertView.findViewById(R.id.item_text); holder.image = (ImageView) convertView.findViewById(R.id.item_microBlogImage); holder.source = (TextView) convertView.findViewById(R.id.item_from); holder.statuses_count = (TextView) convertView.findViewById(R.id.item_tweet_statuses_count); holder.followers_count = (TextView) convertView.findViewById(R.id.item_tweet_followers_count); holder.created_at = (TextView) convertView.findViewById(R.id.item_created_at); holder.verified = (ImageView) convertView.findViewById(R.id.item_vipImage); holder.rt_text = (TextView) convertView.findViewById(R.id.item_retweeted_status_text); holder.rt_image = (ImageView) convertView.findViewById(R.id.item_retweeted_status_microBlogImage); holder.rt_ll = (LinearLayout) convertView.findViewById(R.id.item_retweeted_status_ll); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.name.setText(name); holder.text.setText(text); // image = mStatus.getThumbnailPic(); if (!image_url.equals("")) { imageLoader.displayImage(image_url, holder.image, options); holder.image.setOnClickListener(imageClickListener); holder.image.setTag(R.string.first_tag, image_url); holder.image.setTag(R.string.second_tag, mStatus.getOriginalPic()); holder.image.setVisibility(ImageView.VISIBLE); } else { holder.image.setVisibility(View.GONE); } holder.source.setText(source); if (!avatar_url.equals("")) imageLoader.displayImage(avatar_url, holder.avatar, options); holder.statuses_count.setText(statuses_count + ""); holder.followers_count.setText(followers_count + ""); holder.created_at.setVisibility(View.VISIBLE); if (!created_at.equals("") && created_at != null) holder.created_at.setText(created_at); else holder.created_at.setVisibility(View.INVISIBLE); if (verified) holder.verified.setVisibility(View.VISIBLE); else holder.verified.setVisibility(View.INVISIBLE); // ------------------------转发微博---------------------------------- String rt_text_value = ""; if (retweetedStatus != null) { rt_text_value = retweetedStatus.getText(); Log.v(TAG, "rt_text_value: " + rt_text_value); } else { // do nothing } if (!rt_text_value.equals("")) { holder.rt_text.setVisibility(View.VISIBLE); holder.rt_text.setText(rt_text_value); } else { holder.rt_text.setVisibility(View.GONE); } String rt_Image_url = ""; if (retweetedStatus != null) { rt_Image_url = retweetedStatus.getThumbnailPic(); Log.v(TAG, "rt_Image_url: " + rt_Image_url); } else { // do nothing } if (!rt_Image_url.equals("")) { holder.rt_image.setOnClickListener(imageClickListener); holder.rt_image.setTag(R.string.first_tag, rt_Image_url); holder.rt_image.setTag(R.string.second_tag, retweetedStatus.getOriginalPic()); holder.rt_image.setVisibility(View.VISIBLE); imageLoader.displayImage(rt_Image_url, holder.rt_image, options); } else { holder.rt_image.setVisibility(View.GONE); } if (rt_text_value.equals("") && rt_Image_url.equals("")) holder.rt_ll.setVisibility(View.GONE); else holder.rt_ll.setVisibility(View.VISIBLE); return convertView; }