2 augustiam Augustiam 于 2015.06.03 16:08 提问

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中(都是假数据)。

9个回答

Augustiam
Augustiam   2015.06.03 17:34

不太懂,有哪位可以详细的说下吗?谢谢!

lhfxgcc
lhfxgcc   2015.09.12 10:44

楼主你实现了吗.我最近也在做这个,也是错位,方便的话沟通一下吧1156924412 可以把Demo发一下吗谢了.guochenchn@163.com

bdmh
bdmh   Ds   Rxr 2015.06.03 16:11

数据都在你绑定的数据源中,你在getview中写道item中就行了,获取的话,得到当前item的position,然后根据这个索引去数据源中读取

Augustiam
Augustiam 小白啊,能具体点吗?谢谢!
2 年多之前 回复
datou431
datou431   Rxr 2015.06.18 14:41

获取的话,得到当前item的position,然后根据这个索引去数据源中读取

datou431
datou431   Rxr 2015.06.18 14:40

获取的话,得到当前item的position,然后根据这个索引去数据源中读取

yang_ge_98
yang_ge_98   2015.07.27 11:56

有个问题搞不明白,那个显示点赞信息图标接着文字,文字还会错位显示。这个怎么做。

u013706382
u013706382   2015.12.08 11:53

有没有具体的实现哦?

qq_34133591
qq_34133591   2016.03.01 17:37

求发Demo 1098769776@qq.com

qq_36139453
qq_36139453   2016.09.18 17:09

求发Demo 546781739@qq.com

Csdn user default icon
上传中...
上传图片
插入图片