新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

android怎么实现仿京东商品属性筛选功能-创新互联

这篇“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是一个流式布局:


 
 
   
 
   
   

整个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 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(); 
     } 
    }

以上就是关于“android怎么实现仿京东商品属性筛选功能”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注创新互联行业资讯频道。


本文名称:android怎么实现仿京东商品属性筛选功能-创新互联
网址分享:http://www.wjwzjz.com/article/gspsd.html
在线咨询
服务热线
服务热线:028-86922220
TOP