问题描述
- android 类似微信朋友圈点赞,评论功能怎么实现?
-
@Override
public int getCount() {
return 5;
}@Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public int getItemViewType(int position) { // TODO Auto-generated method stub switch (position) { case 0: return TYPE_1; case 1: return TYPE_2; case 2: return TYPE_3; default: return 0; } } @Override public int getViewTypeCount() { // TODO Auto-generated method stub return 3; } @Override public View getView(int position, View convertView, ViewGroup parent) { holder1 = null; holder2 = null; holder3 = null; int type = getItemViewType(position); if (convertView == null) { mInflater = LayoutInflater.from(mContext); switch (type) { case TYPE_1: convertView = mInflater.inflate(R.layout.lv_find_item, null); holder1 = new Holder1(); holder1.gridView = (GridView) convertView .findViewById(R.id.gridView_find); holder1.btn_show_feed = (ImageView) convertView .findViewById(R.id.btn_show_feed); holder1.tv_share_names = (TextView) convertView .findViewById(R.id.tv_share_names); holder1.tv_share = (TextView) convertView .findViewById(R.id.tv_share); holder1.tv_add_friend = (TextView) convertView .findViewById(R.id.tv_add_friend); convertView.setTag(holder1); break; case TYPE_2: convertView = mInflater.inflate(R.layout.lv_find_item2, null); holder2 = new Holder2(); holder2.btn_show_feed2 = (ImageView) convertView .findViewById(R.id.btn_show_feed2); holder2.tv_share_names2 = (TextView) convertView .findViewById(R.id.tv_share_names2); holder2.tv_share2 = (TextView) convertView .findViewById(R.id.tv_share2); holder2.tv_add_friend2 = (TextView) convertView .findViewById(R.id.tv_add_friend2); convertView.setTag(holder2); break; case TYPE_3: convertView = mInflater.inflate(R.layout.lv_find_item3, null); holder3 = new Holder3(); holder3.gridView3 = (GridView) convertView .findViewById(R.id.gridView3); holder3.btn_show_feed3 = (ImageView) convertView .findViewById(R.id.btn_show_feed3); holder3.tv_share_names3 = (TextView) convertView .findViewById(R.id.tv_share_names3); holder3.tv_share3 = (TextView) convertView .findViewById(R.id.tv_share3); holder3.tv_add_friend3 = (TextView) convertView .findViewById(R.id.tv_add_friend3); holder3.tv_crowdfunding_record3 = (TextView) convertView .findViewById(R.id.tv_crowdfunding_record3); convertView.setTag(holder3); break; default: break; } } else { switch (type) { case TYPE_1: holder1 = (Holder1) convertView.getTag(); break; case TYPE_2: holder2 = (Holder2) convertView.getTag(); break; case TYPE_3: holder3 = (Holder3) convertView.getTag(); break; } } // 设置资源 switch (type) { case TYPE_1: holder1.gridView.setAdapter(new HomeBuyGridAdapter(mContext, images_buy)); holder1.btn_show_feed.setOnClickListener(new PopClicListener(type)); holder1.tv_share.setOnClickListener(new MyShareListener()); holder1.tv_add_friend.setOnClickListener(new MyAddListener()); break; case TYPE_2: holder2.btn_show_feed2 .setOnClickListener(new PopClicListener(type)); holder2.tv_share2.setOnClickListener(new MyShareListener()); holder2.tv_add_friend2.setOnClickListener(new MyAddListener()); break; case TYPE_3: holder3.gridView3.setAdapter(new HomeBuyGridAdapter(mContext, images_buy)); holder3.btn_show_feed3 .setOnClickListener(new PopClicListener(type)); holder3.tv_share3.setOnClickListener(new MyShareListener()); holder3.tv_add_friend3.setOnClickListener(new MyAddListener()); holder3.tv_crowdfunding_record3 .setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub getUpPop(); popCrowdfunding.showAtLocation(v, Gravity.CENTER, 0, 0); } }); break; } return convertView; } class Holder1 { GridView gridView; ImageView btn_show_feed; TextView tv_add_friend; TextView tv_share; TextView tv_share_names; TextView tv_comment_name; TextView tv_comment_content; LinearLayout ll_comment; LinearLayout ll_reply; } class Holder2 { ImageView btn_show_feed2; TextView tv_add_friend2; TextView tv_share2; TextView tv_share_names2; TextView tv_comment_name2; TextView tv_comment_content2; LinearLayout ll_comment2; LinearLayout ll_reply2; } class Holder3 { GridView gridView3; ImageView btn_show_feed3; TextView tv_add_friend3; TextView tv_share3; TextView tv_crowdfunding_record3; TextView tv_share_names3; TextView tv_comment_name3; TextView tv_comment_content3; LinearLayout ll_comment3; LinearLayout ll_reply3; }
加载三种不同布局是这样写的吧?有更好的方式吗?
我现在做的一个类似的功能,listview里面加载了三种不同的布局,每种布局都有点赞,评论功能。都是点击按钮弹出一个popupwindow,里面有点赞,评论,按钮。
怎么在点赞的时候能让昵称显示在listview中呢?且显示在对应的listview的item中(都是假数据)。
解决方案
楼主你实现了吗.我最近也在做这个,也是错位,方便的话沟通一下吧1156924412 可以把Demo发一下吗谢了.guochenchn@163.com
解决方案二:
数据都在你绑定的数据源中,你在getview中写道item中就行了,获取的话,得到当前item的position,然后根据这个索引去数据源中读取
解决方案三:
不太懂,有哪位可以详细的说下吗?谢谢!
解决方案四:
获取的话,得到当前item的position,然后根据这个索引去数据源中读取
解决方案五:
获取的话,得到当前item的position,然后根据这个索引去数据源中读取
解决方案六:
有个问题搞不明白,那个显示点赞信息图标接着文字,文字还会错位显示。这个怎么做。
解决方案七:
有没有具体的实现哦?
解决方案八:
求发Demo 1098769776@qq.com
时间: 2025-01-01 23:39:13