国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

android仿京東商品屬性篩選功能

2019-10-22 18:21:29
字體:
來源:轉載
供稿:網友

篩選和屬性選擇是目前非常常用的功能模塊;幾乎所有的APP中都會使用;

android,商品篩選,商品屬性篩選,android京東商品屬性篩選,android商品屬性選擇

點擊篩選按鈕會彈出一個自己封裝好的popupWindow,實用方法非常簡單;兩行代碼直接顯示;(當然初始化數據除外)

這里和以前用到的流式布局有些不一樣:流式布局

以前使用的是單個分類,而且也沒有在項目中大量實用;這個篩選功能除了數據外幾乎都是從項目中Copy出來的;

整個popupWindow布局就是一個自定義的ListView,這個自定義的listview主要是控制listview的高度;

如果數據少的話就是自適應,如果數據多了就限制高度為屏幕的一半;

自定義的ListView:

public class CustomHeightListView extends ListView {    private Context mContext;    public CustomHeightListView(Context context) {     this(context, null);   }    public CustomHeightListView(Context context, AttributeSet attrs) {     this(context, attrs, 0);   }    public CustomHeightListView(Context context, AttributeSet attrs, int defStyleAttr) {     super(context, attrs, defStyleAttr);     init(context);   }    private void init(Context context) {     mContext = context;   }    @Override   protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {     try {       //最大高度顯示為屏幕內容高度的一半       Display display = ((Activity) mContext).getWindowManager().getDefaultDisplay();       DisplayMetrics d = new DisplayMetrics();       display.getMetrics(d);       //設置控件高度不能超過屏幕高度一半(d.heightPixels / 2,下面有清空按鈕所以再減200,也可隨意換成自己想要的高度)       heightMeasureSpec = MeasureSpec.makeMeasureSpec(d.heightPixels / 2 - 200, MeasureSpec.AT_MOST);     } catch (Exception e) {       e.printStackTrace();     }     //重新計算控件高、寬     super.onMeasure(widthMeasureSpec, heightMeasureSpec);   } } 

ListView中每個item是一個流式布局:

<LinearLayout xmlns:android/140099.html">android="http://schemas.android.com/apk/res/android"   android:layout_width="match_parent"   android:layout_height="wrap_content"   android:orientation="vertical">    <TextView     android:id="@+id/tv_type_name"     android:layout_width="match_parent"     android:layout_height="wrap_content" />    <com.example.zheng.flowlayoutdemo.view.SkuFlowLayout     android:id="@+id/layout_property"     android:layout_width="match_parent"     android:layout_height="wrap_content" />    </LinearLayout> 

整個popupwindow都封裝在一個類中,創建的時候只需把數據源傳遞過去即可,實用的時候直接show就可以了

flowPopWindow = new FlowPopWindow(MainActivity.this, dictList);     flowPopWindow.showAsDropDown(ivBack); 

當點擊確定的時候直接設置一個監聽即可:

flowPopWindow.setOnConfirmClickListener(new FlowPopWindow.OnConfirmClickListener() {      @Override      public void onConfirmClick() {       StringBuilder sb = new StringBuilder();       for (FiltrateBean fb : dictList) {        List<FiltrateBean.Children> cdList = fb.getChildren();        for (int x = 0; x < cdList.size(); x++) {         FiltrateBean.Children children = cdList.get(x);         if (children.isSelected())          sb.append(fb.getTypeName() + ":" + children.getValue() + ";");        }       }       if (!TextUtils.isEmpty(sb.toString()))        Toast.makeText(MainActivity.this, sb.toString(), Toast.LENGTH_LONG).show();      }     } 

點擊打開鏈接免費下載源碼

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 山丹县| 自治县| 兴安县| 郁南县| 麦盖提县| 咸丰县| 望江县| 宜昌市| 焉耆| 鹤岗市| 绍兴市| 冷水江市| 汶川县| 甘洛县| 乐安县| 英吉沙县| 顺义区| 鄢陵县| 景德镇市| 遂川县| 沈阳市| 嘉峪关市| 遵义市| 安泽县| 炉霍县| 阿荣旗| 平舆县| 台山市| 长武县| 乌审旗| 涞水县| 翁牛特旗| 新密市| 全州县| 汶上县| 夏津县| 大厂| 庆元县| 泸水县| 滦南县| 确山县|