商品详情页<商品属性选择,包含多规格>

近一年的时间没有更新过博客了,主要是在着手一个电商APP , 现在APP也上线了所以有时间整理一下这段时间踩过的一些坑,以及做过的一些常用功能。


商品详情属性选择是一个商城APP中相当常见的功能,思路如下:
一、自定义Dialog,用来展示商品信息以及商品规格等。
二、自定义View Group , 用来装载商品的规格以及属性。

代码就不贴了,Demo下载地址


查漏补缺

1.Bug : 当listview超出Didlog视图的时候,滑动listview会导致被选中的属性规格刷新,不能正常保存选中状态.

解决方法:将listview适配器中的getView方法代码块改成以下代码:

 @Override
    public View getView(int position, View view, ViewGroup viewGroup) {

        if (view == null){
            view = LayoutInflater.from(context).inflate(R.layout.emp_dialog_item, null);
            TextView type_txt = (TextView) view.findViewById(R.id.type_txt);
            String type = (String) dateModle.getGoods_types().get(position).getAttr_name()+" :";
            type_txt.setText(type);
            type_txt.setTextColor(Color.parseColor("#a1a1a1"));
            mFlowLayout = (BaseFlowLayout) view.findViewById(R.id.news_top_title_base_flowlayout);
            lables = dateModle.getGoods_types().get(position).getAttr_list();
            if (mFlowLayout.getChildCount() == 0){
                TextView[]  textViews = new TextView[lables.size()];
                String[] type_url = new String[lables.size()];
                for (int i = 0; i < lables.size(); i++) {
                    TextView tv = (TextView) LayoutInflater.from(context).inflate(R.layout.news_top_title_search_, mFlowLayout, false);
                    textViews[i] = tv;
                    if (i == 0){
                        textViews[i].setBackgroundResource(R.drawable.news_top_title_search_label_bg);
                        textViews[i].setTextColor(Color.parseColor("#FFFFFF"));
                    }else {
                        textViews[i].setBackgroundResource(R.drawable.news_top_title_search_bg);
                        textViews[i].setTextColor(Color.parseColor("#535353"));
                    }
                    textViews[i].setText(lables.get(i).getAttr_value());
                    textViews[i].setTag(i);
                    type_url[i] = lables.get(i).getImg_url();   //对应的id
                    mFlowLayout.addView(textViews[i]);//添加到父View
                }
                //绑定标签的Click事件
                for(int j = 0 ; j < textViews.length;j++){
                    textViews[j].setTag(textViews);
                    textViews[j].setOnClickListener(new LableClickListener(type,type_url));
                }
            }
            view.setTag(mFlowLayout);
        }
        else {
            view.getTag();
        }
        return view;
    }

效果图如下:

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述


项目中的数据都是定义的假数据,如果想要应用到自己的项目当中,替换一下数据类就可以了。

  • 6
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值