当前位置: 移动技术网 > IT编程>移动开发>Android > android仿京东商品属性筛选功能

android仿京东商品属性筛选功能

2019年07月24日  | 移动技术网IT编程  | 我要评论

那些年 胡夏 mp3,妹妹恋人ova,安徽省二本院校排名

筛选和属性选择是目前非常常用的功能模块;几乎所有的app中都会使用;

点击筛选按钮会弹出一个自己封装好的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="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(); 
     } 
    } 

点击打开链接免费

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网