本文实例为大家分享了Android实现朋友圈评论回复列表的具体代码,供大家参考,具体内容如下Android实现朋友圈评论回复列表Android实现朋友圈点赞列表Android实现朋友圈多图显示功能正文还是老流程,先来看一下效果图:然后是主要
本文实例为大家分享了Android实现朋友圈评论回复列表的具体代码,供大家参考,具体内容如下
Android实现朋友圈评论回复列表
Android实现朋友圈点赞列表
Android实现朋友圈多图显示功能
正文
还是老流程,先来看一下效果图:
然后是主要实现代码:
CommentsView
public class CommentsView extends LinearLayout { private Context mContext; private List<CommentsBean> mDatas; private onItemClickListener listener; public CommentsView(Context context) { this(context, null); } public CommentsView(Context context, @Nullable AttributeSet attrs) { this(context, attrs, 0); } public CommentsView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setOrientation(VERTICAL); this.mContext = context; } public void setList(List<CommentsBean> list) { mDatas = list; } public void setOnItemClickListener(onItemClickListener listener) { this.listener = listener; } public void notifyDataSetChanged() { removeAllViews(); if (mDatas == null || mDatas.size() <= 0) { return; } LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(0, 10, 0, 10); for (int i = 0; i < mDatas.size(); i++) { View view = getView(i); if (view == null) { throw new NullPointerException("listview item layout is null, please check getView()..."); } addView(view, i, layoutParams); } } private View getView(final int position) { final CommentsBean item = mDatas.get(position); UserBean replyUser = item.getReplyUser(); boolean hasReply = false; // 是否有回复 if (replyUser != null) { hasReply = true; } TextView textView = new TextView(mContext); textView.setTextSize(15); textView.setTextColor(0xff686868); SpannableStringBuilder builder = new SpannableStringBuilder(); UserBean comUser = item.getCommentsUser(); String name = comUser.getUserName(); if (hasReply) { builder.append(setClickableSpan(name, item.getCommentsUser())); builder.append(" 回复 "); builder.append(setClickableSpan(replyUser.getUserName(), item.getReplyUser())); } else { builder.append(setClickableSpan(name, item.getCommentsUser())); } builder.append(" : "); builder.append(setClickableSpanContent(item.getContent(), position)); textView.setText(builder); // 设置点击背景色 textView.setHighlightColor(getResources().getColor(android.R.color.transparent));// textView.setHighlightColor(0xff000000); textView.setMovementMethod(new CircleMovementMethod(0xffcccccc, 0xffcccccc)); textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (listener != null) { listener.onItemClick(position, item); } } }); return textView; } public SpannableString setClickableSpanContent(final String item, final int position) { final SpannableString string = new SpannableString(item); ClickableSpan span = new ClickableSpan() { @Override public void onClick(View widget) { // TODO: 2017/9/3 评论内容点击事件 Toast.makeText(mContext, "position: " + position + " , content: " + item, Toast.LENGTH_SHORT).show(); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); // 设置显示的内容文本颜色 ds.setColor(0xff686868); ds.setUnderlineText(false); } }; string.setSpan(span, 0, string.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return string; } public SpannableString setClickableSpan(final String item, final UserBean bean) { final SpannableString string = new SpannableString(item); ClickableSpan span = new ClickableSpan() { @Override public void onClick(View widget) { // TODO: 2017/9/3 评论用户名字点击事件 Toast.makeText(mContext, bean.getUserName(), Toast.LENGTH_SHORT).show(); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); // 设置显示的用户名文本颜色 ds.setColor(0xff387dcc); ds.setUnderlineText(false); } }; string.setSpan(span, 0, string.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return string; } public interface onItemClickListener { void onItemClick(int position, CommentsBean bean); }}
--结束END--
本文标题: Android实现朋友圈评论回复列表
本文链接: https://www.lsjlt.com/news/220007.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0