@Override public View getView(int position, View convertView, ViewGroup parent) { MyViewHolder mViewHolder; if (convertView == null) { convertView = inflater.inflate(R.layout.layout_list_item, null); mViewHolder = new MyViewHolder(); convertView.setTag(mViewHolder); } else { mViewHolder = (MyViewHolder) convertView.getTag(); } mViewHolder.title = detail( convertView, R.id.textview1, arrayListThongTinFaceBook.get(position).id + "\t " + arrayListThongTinFaceBook.get(position).name + "\t" + arrayListThongTinFaceBook.get(position).gender); // return null; mViewHolder.description = detail( convertView, R.id.textview2, arrayListThongTinFaceBook.get(position).email + "\t" + arrayListThongTinFaceBook.get(position).address + "\t" + arrayListThongTinFaceBook.get(position).getPhoneList()); return convertView; }
@Override public void onBindChildViewHolder( AbstractExpandableItemViewHolder holder, int groupPosition, int childPosition, int viewType) { BindableChild data = manager.getDataSet().get(groupPosition).getChildren().get(childPosition); ((MyViewHolder) holder).textView.setText(data.getText()); }
@Override public void onBindViewHolder(MyViewHolder holder, int position) { final AbstractDataProvider.Data item = mProvider.getItem(position); // set text holder.mTextView.setText(item.getText()); // set background resource (target view ID: container) final int dragState = holder.getDragStateFlags(); if (((dragState & Draggable.STATE_FLAG_IS_UPDATED) != 0)) { int bgResId; if ((dragState & Draggable.STATE_FLAG_IS_ACTIVE) != 0) { bgResId = R.drawable.bg_item_dragging_active_state; // need to clear drawable state here to get correct appearance of the dragging item. DrawableUtils.clearState(holder.mContainer.getForeground()); } else if ((dragState & Draggable.STATE_FLAG_DRAGGING) != 0) { bgResId = R.drawable.bg_item_dragging_state; } else { bgResId = R.drawable.bg_item_normal_state; } holder.mContainer.setBackgroundResource(bgResId); } }
@Override public void onBindViewHolder(MyViewHolder holder, int position) { holder.updatePosition(position); convert(holder, mDatas.get(position)); }
@Override public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return MyViewHolder.get(mContext, parent, mLayoutId); }
@Override public void onBindViewHolder(MyViewHolder myViewHolder, int i) { myViewHolder.onBind(); }
@Override public void onBindViewHolder(final MyViewHolder viewHolder, int position) { post = list.get(position); iv_avator = (ImageView) viewHolder.getView(R.id.iv_avator); TextView tv_author = (TextView) viewHolder.getView(R.id.tv_author); TextView tv_time = (TextView) viewHolder.getView(R.id.tv_time); TextView tv_content = (TextView) viewHolder.getView(R.id.tv_content); tv_praise = (TextView) viewHolder.getView(R.id.tv_praise); tv_reply = (TextView) viewHolder.getView(R.id.tv_reply); btn_praise = (Button) viewHolder.getView(R.id.btn_praise); btn_share = (Button) viewHolder.getView(R.id.btn_share); btn_reply = (Button) viewHolder.getView(R.id.btn_reply); ll_praise = (LinearLayout) viewHolder.getView(R.id.ll_praise); ll_share = (LinearLayout) viewHolder.getView(R.id.ll_share); iv_sex = (ImageView) viewHolder.getView(R.id.iv_sex); if (post.getAuthor().getSex().equals("男")) { iv_sex.setImageResource(R.drawable.blue_male); } else { iv_sex.setImageResource(R.drawable.red_female); } tv_praise.setTag(position); tv_praise.setText("赞"); if (post.getPraiseCount() == 0) { tv_praise.setText("赞"); } else { tv_praise.setText(post.getPraiseCount() + ""); } tv_reply.setText("评论"); BmobQuery<Reply> query = new BmobQuery<Reply>(); query.addWhereEqualTo("post", post); query.count( context, Reply.class, new CountListener() { @Override public void onSuccess(int i) { if (i != 0) { tv_reply.setText(i + ""); } } @Override public void onFailure(int i, String s) {} }); iv_avator.setOnClickListener(this); iv_avator.setTag(position); ll_praise.setOnClickListener(this); ll_praise.setTag(position); ll_share.setOnClickListener(this); ll_share.setTag(position); if (post.getIsPraise()) { btn_praise.setBackgroundResource(R.drawable.praise_press); } else { btn_praise.setBackgroundResource(R.drawable.praise_normal); } String avatar = post.getAvator(); if (avatar != null && !avatar.equals("")) { ImageLoader.getInstance().displayImage(avatar, iv_avator, ImageLoadOptions.getOptions()); } else { if (post.getAuthor().getSex().equals("男")) { iv_avator.setImageResource(R.mipmap.male_default_icon); } else { iv_avator.setImageResource(R.mipmap.female_default_icon); } } // 设置时间 long time = TimeUtil.stringToLong(post.getCreatedAt(), "yyyy-MM-dd HH:mm:ss"); tv_time.setText(TimeUtil.getDescriptionTimeFromTimestamp(time)); // 设置用户名 tv_author.setText(post.getAuthor().getNick()); // 设置文字内容 SpannableString spannableString = FaceTextUtil.toSpannableString(context, post.getContent()); tv_content.setText(spannableString); tv_content.setVisibility(View.VISIBLE); final List<String> imagesUrl = post.getImages(); iv_content = (ImageView) viewHolder.getView(R.id.iv_content); if (imagesUrl != null && imagesUrl.size() > 0) { // 只取出第一张图片 String url = imagesUrl.get(0); iv_content.setVisibility(View.VISIBLE); ImageLoader.getInstance().displayImage(url, iv_content, ImageLoadOptions.getOptions()); } else { // layout_content.setVisibility(View.GONE); iv_content.setVisibility(View.GONE); } iv_content.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(context, ImageBrowserActivity.class); ArrayList<String> photos = new ArrayList<String>(); photos.add(imagesUrl.get(0)); intent.putStringArrayListExtra("photos", photos); intent.putExtra("position", 0); context.startActivity(intent); } }); // 如果设置了回调,则设置点击事件 if (mOnItemClickLitener != null) { view.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { int pos = viewHolder.getLayoutPosition(); mOnItemClickLitener.onItemClick(view, pos); } }); view.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { int pos = viewHolder.getLayoutPosition(); mOnItemClickLitener.onItemLongClick(view, pos); return false; } }); } }