近一年的时间没有更新过博客了,主要是在着手一个电商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;
}
效果图如下:
项目中的数据都是定义的假数据,如果想要应用到自己的项目当中,替换一下数据类就可以了。