├── bin
├── classes.dex
├── resources.ap_
├── ExpandableView.apk
├── res
│ └── crunch
│ │ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ ├── ic_launcher.png
│ │ ├── choosearea_bg_right.9.png
│ │ └── index_icon_targetdown_grey.png
│ │ └── drawable-xxhdpi
│ │ ├── ic_launcher.png
│ │ ├── choosebar_line.png
│ │ └── index_icon_targetdown_grey.png
├── classes
│ └── com
│ │ └── example
│ │ └── expandableview
│ │ ├── R.class
│ │ ├── R$id.class
│ │ ├── R$anim.class
│ │ ├── R$attr.class
│ │ ├── R$color.class
│ │ ├── R$dimen.class
│ │ ├── R$layout.class
│ │ ├── R$string.class
│ │ ├── R$style.class
│ │ ├── BuildConfig.class
│ │ ├── R$drawable.class
│ │ ├── ExpandableView.class
│ │ ├── MainActivity.class
│ │ ├── ExpandableView$1.class
│ │ ├── ExpandableView$2.class
│ │ ├── ExpandableView$3.class
│ │ ├── ExpandleItemView.class
│ │ ├── ExpandleItemView$1.class
│ │ ├── ExpandleItemView$2.class
│ │ ├── ExpandleItemView$3.class
│ │ ├── adapter
│ │ ├── ViewHolder.class
│ │ └── MyBaseAdapter.class
│ │ └── ExpandleItemView$OnExpandItemClick.class
└── AndroidManifest.xml
├── ic_launcher-web.png
├── README.md
├── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ ├── ic_launcher.png
│ ├── choosearea_bg_right.9.png
│ └── index_icon_targetdown_grey.png
├── drawable-xxhdpi
│ ├── ic_launcher.png
│ ├── choosebar_line.png
│ └── index_icon_targetdown_grey.png
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
├── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── layout
│ ├── line.xml
│ ├── gridview_item.xml
│ ├── activity_main.xml
│ ├── toggle_button.xml
│ └── expand_item_layout.xml
├── drawable
│ ├── bottom_selector.xml
│ ├── btn_selctor.xml
│ ├── grid_item_selected.xml
│ └── grid_item_unselected.xml
├── values-w820dp
│ └── dimens.xml
└── anim
│ ├── pophidden_anim.xml
│ └── popshow_anim.xml
├── gen
└── com
│ └── example
│ └── expandableview
│ ├── BuildConfig.java
│ └── R.java
├── project.properties
├── proguard-project.txt
├── AndroidManifest.xml
└── src
└── com
└── example
└── expandableview
├── MainActivity.java
├── adapter
├── MyBaseAdapter.java
└── ViewHolder.java
├── ExpandleItemView.java
└── ExpandableView.java
/bin/classes.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes.dex
--------------------------------------------------------------------------------
/bin/resources.ap_:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/resources.ap_
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/ic_launcher-web.png
--------------------------------------------------------------------------------
/bin/ExpandableView.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/ExpandableView.apk
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ExpandableView
2 | #
3 | Android 自定义分层级筛选控件
4 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/choosebar_line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/res/drawable-xxhdpi/choosebar_line.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/res/crunch/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/res/crunch/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/choosearea_bg_right.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/res/drawable-xhdpi/choosearea_bg_right.9.png
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/R.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/R.class
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/res/crunch/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/res/crunch/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/R$id.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/R$id.class
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-xxhdpi/choosebar_line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/res/crunch/drawable-xxhdpi/choosebar_line.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/index_icon_targetdown_grey.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/res/drawable-xhdpi/index_icon_targetdown_grey.png
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/R$anim.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/R$anim.class
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/R$attr.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/R$attr.class
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/index_icon_targetdown_grey.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/res/drawable-xxhdpi/index_icon_targetdown_grey.png
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/R$color.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/R$color.class
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/R$dimen.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/R$dimen.class
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/R$layout.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/R$layout.class
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/R$string.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/R$string.class
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/R$style.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/R$style.class
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/BuildConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/BuildConfig.class
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/R$drawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/R$drawable.class
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-xhdpi/choosearea_bg_right.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/res/crunch/drawable-xhdpi/choosearea_bg_right.9.png
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/ExpandableView.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/ExpandableView.class
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/MainActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/MainActivity.class
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/ExpandableView$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/ExpandableView$1.class
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/ExpandableView$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/ExpandableView$2.class
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/ExpandableView$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/ExpandableView$3.class
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/ExpandleItemView.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/ExpandleItemView.class
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-xhdpi/index_icon_targetdown_grey.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/res/crunch/drawable-xhdpi/index_icon_targetdown_grey.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-xxhdpi/index_icon_targetdown_grey.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/res/crunch/drawable-xxhdpi/index_icon_targetdown_grey.png
--------------------------------------------------------------------------------
/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/ExpandleItemView$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/ExpandleItemView$1.class
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/ExpandleItemView$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/ExpandleItemView$2.class
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/ExpandleItemView$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/ExpandleItemView$3.class
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/adapter/ViewHolder.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/adapter/ViewHolder.class
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/adapter/MyBaseAdapter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/adapter/MyBaseAdapter.class
--------------------------------------------------------------------------------
/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #a6aebb
5 | #90eeeeee
6 |
7 |
--------------------------------------------------------------------------------
/bin/classes/com/example/expandableview/ExpandleItemView$OnExpandItemClick.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuangmin/ExpandableView/HEAD/bin/classes/com/example/expandableview/ExpandleItemView$OnExpandItemClick.class
--------------------------------------------------------------------------------
/gen/com/example/expandableview/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.example.expandableview;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/res/layout/line.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ExpandableView
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/drawable/bottom_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/res/drawable/btn_selctor.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
--------------------------------------------------------------------------------
/res/drawable/grid_item_selected.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/res/drawable/grid_item_unselected.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 | 64dp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/res/layout/gridview_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/res/anim/pophidden_anim.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/res/anim/popshow_anim.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-21
15 |
--------------------------------------------------------------------------------
/res/layout/toggle_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/bin/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/res/layout/expand_item_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
18 |
19 |
21 |
22 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/com/example/expandableview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.expandableview;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.LinkedHashMap;
6 | import java.util.Map;
7 |
8 | import android.app.Activity;
9 | import android.os.Bundle;
10 |
11 | public class MainActivity extends Activity {
12 | private ExpandableView mExpandableView;
13 | private Map mExpandleItemViews;
14 | private String[] mColleages = { "A学校", "B学校", "C学校", "D学校", "E学校", "F学校", "G学校", "H学校", "I学校", "J学校" };
15 | private String[] mDepartments = { "A系", "B系", "C系", "D系", "E系", "F系", "G系", "H系" , "I系" };
16 | private String[] mProfessions = { "A专业", "B专业", "C专业" , "D专业" , "E专业" , "F专业" };
17 | private String[] mClasses = { "A班", "B班", "C班", "D班" , "E班" };
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_main);
23 | mExpandableView = (ExpandableView) findViewById(R.id.expandview);
24 | mExpandleItemViews = new LinkedHashMap<>();
25 | //不要问我为什么这么用,因为我想用LinkedHashMap
26 | mExpandleItemViews.put("大学", new ExpandleItemView("大学", this, Arrays.asList(mColleages)));
27 | mExpandleItemViews.put("院系", new ExpandleItemView("院系", this, Arrays.asList(mDepartments)));
28 | mExpandleItemViews.put("专业", new ExpandleItemView("专业", this, Arrays.asList(mProfessions)));
29 | mExpandleItemViews.put("班级", new ExpandleItemView("班级", this, Arrays.asList(mClasses)));
30 | mExpandableView.initViews(new ArrayList<>(mExpandleItemViews.values()));
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/com/example/expandableview/adapter/MyBaseAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.expandableview.adapter;
2 |
3 | import java.util.List;
4 |
5 | import android.content.Context;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.BaseAdapter;
10 |
11 |
12 | /**
13 | * Created by rander on 16-3-24.
14 | */
15 | public abstract class MyBaseAdapter extends BaseAdapter {
16 | protected List datas;
17 | protected int layoutId;
18 | protected LayoutInflater layoutInflater;
19 | protected Context mContext;
20 |
21 | public MyBaseAdapter(List datas, int layoutId,Context mContext) {
22 | this.datas = datas;
23 | this.layoutId = layoutId;
24 | this.mContext = mContext;
25 | this.layoutInflater = LayoutInflater.from(mContext);
26 | }
27 |
28 | @Override
29 | public int getCount() {
30 | return null == datas ? 0 : datas.size();
31 | }
32 |
33 | @Override
34 | public Object getItem(int position) {
35 | return null == datas ? null : datas.size() > position ? datas.get(position) : null;
36 | }
37 |
38 | @Override
39 | public long getItemId(int position) {
40 | return position;
41 | }
42 |
43 | @Override
44 | public View getView(int position, View convertView, ViewGroup parent) {
45 | return getView(position, convertView, parent,layoutId);
46 | }
47 |
48 | public View getView(int position, View convertView, ViewGroup parent, int layoutId)
49 | {
50 | ViewHolder viewHolder = ViewHolder.get(position, convertView, parent, layoutId, mContext);
51 | convert(viewHolder,datas.get(position));
52 | return viewHolder.getmContentView();
53 | }
54 |
55 | protected abstract void convert(ViewHolder viewHolder, T t);
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/com/example/expandableview/adapter/ViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.example.expandableview.adapter;
2 |
3 | import android.content.Context;
4 | import android.util.SparseArray;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.TextView;
9 |
10 | /**
11 | * Created by rander on 16-3-24.
12 | */
13 | public class ViewHolder {
14 | private SparseArray mViews;
15 | private LayoutInflater layoutInflater;
16 | private View mContentView;
17 | public ViewHolder(int itemLayoutId,ViewGroup parent, Context mContext) {
18 | mViews = new SparseArray();
19 | layoutInflater = LayoutInflater.from(mContext);
20 | mContentView = layoutInflater.inflate(itemLayoutId, parent, false);
21 | mContentView.setTag(this);
22 | }
23 |
24 | public static ViewHolder get(int position, View convertView, ViewGroup parent,int layoutId,Context context)
25 | {
26 | ViewHolder viewHolder;
27 | if(convertView == null)
28 | {
29 | viewHolder = new ViewHolder(layoutId,parent,context);
30 | }
31 | else
32 | {
33 | viewHolder = (ViewHolder) convertView.getTag();
34 | }
35 | return viewHolder;
36 | }
37 |
38 | public T getView(int viewId) {
39 | View v = mViews.get(viewId);
40 | if (v == null) {
41 | v = mContentView.findViewById(viewId);
42 | mViews.put(viewId, v);
43 | }
44 | return (T)v;
45 | }
46 |
47 | public ViewHolder setTvText(int viewId,String str)
48 | {
49 | TextView v = getView(viewId);
50 | v.setText(str);
51 | return this;
52 | }
53 |
54 | public ViewHolder setBtnText(int viewId,String str)
55 | {
56 | TextView v = getView(viewId);
57 | v.setText(str);
58 | return this;
59 | }
60 |
61 |
62 | public View getmContentView() {
63 | return mContentView;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/gen/com/example/expandableview/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package com.example.expandableview;
9 |
10 | public final class R {
11 | public static final class anim {
12 | public static final int pophidden_anim=0x7f040000;
13 | public static final int popshow_anim=0x7f040001;
14 | }
15 | public static final class attr {
16 | }
17 | public static final class color {
18 | public static final int grey=0x7f050000;
19 | public static final int grey_bg=0x7f050001;
20 | }
21 | public static final class dimen {
22 | /** Default screen margins, per the Android Design guidelines.
23 |
24 | Example customization of dimensions originally defined in res/values/dimens.xml
25 | (such as screen margins) for screens with more than 820dp of available width. This
26 | would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively).
27 |
28 | */
29 | public static final int activity_horizontal_margin=0x7f060000;
30 | public static final int activity_vertical_margin=0x7f060001;
31 | }
32 | public static final class drawable {
33 | public static final int bottom_selector=0x7f020000;
34 | public static final int btn_selctor=0x7f020001;
35 | public static final int choosearea_bg_right=0x7f020002;
36 | public static final int choosebar_line=0x7f020003;
37 | public static final int grid_item_selected=0x7f020004;
38 | public static final int grid_item_unselected=0x7f020005;
39 | public static final int ic_launcher=0x7f020006;
40 | public static final int index_icon_targetdown_grey=0x7f020007;
41 | }
42 | public static final class id {
43 | public static final int btn_all=0x7f090002;
44 | public static final int expandview=0x7f090000;
45 | public static final int gridview=0x7f090001;
46 | public static final int item_text=0x7f090003;
47 | }
48 | public static final class layout {
49 | public static final int activity_main=0x7f030000;
50 | public static final int expand_item_layout=0x7f030001;
51 | public static final int gridview_item=0x7f030002;
52 | public static final int line=0x7f030003;
53 | public static final int toggle_button=0x7f030004;
54 | }
55 | public static final class string {
56 | public static final int action_settings=0x7f070002;
57 | public static final int app_name=0x7f070000;
58 | public static final int hello_world=0x7f070001;
59 | }
60 | public static final class style {
61 | public static final int AppBaseTheme=0x7f080000;
62 | public static final int AppTheme=0x7f080001;
63 | public static final int PopupWindowAnimation=0x7f080002;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/com/example/expandableview/ExpandleItemView.java:
--------------------------------------------------------------------------------
1 | package com.example.expandableview;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.example.expandableview.adapter.MyBaseAdapter;
7 | import com.example.expandableview.adapter.ViewHolder;
8 |
9 | import android.content.Context;
10 | import android.util.AttributeSet;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.widget.AdapterView;
14 | import android.widget.AdapterView.OnItemClickListener;
15 | import android.widget.Button;
16 | import android.widget.GridView;
17 | import android.widget.LinearLayout;
18 |
19 | public class ExpandleItemView extends LinearLayout {
20 | /**显示在toggleButton的标题文字*/
21 | public String mTitle;
22 | /** 底部按钮 */
23 | private Button mBottomBtn;
24 | /** 展示要筛选的数据*/
25 | private GridView mGridView;
26 | /** 筛选的数据内容*/
27 | private List mGridviewDatas;
28 |
29 | public ExpandleItemView(Context context, AttributeSet attrs, int defStyleAttr) {
30 | super(context, attrs, defStyleAttr);
31 | }
32 |
33 | public ExpandleItemView(Context context, AttributeSet attrs) {
34 | this(context, attrs, -1);
35 | }
36 |
37 | public ExpandleItemView(Context context) {
38 | this(context, null);
39 | }
40 |
41 | public ExpandleItemView(String title, Context context,List datas) {
42 | this(context);
43 | setTitle(title);
44 | mGridviewDatas = datas;
45 | init();
46 | }
47 |
48 | private void init() {
49 | setBackgroundColor(getResources().getColor(android.R.color.white));
50 | /**将布局inflate到此视图中*/
51 | LayoutInflater.from(getContext()).inflate(R.layout.expand_item_layout, this, true);
52 | setOrientation(LinearLayout.VERTICAL);
53 |
54 | mGridView = (GridView) findViewById(R.id.gridview);
55 | mBottomBtn = (Button) findViewById(R.id.btn_all);
56 | /**自己写的万能适配器,一句话就使用了*/
57 | mGridView.setAdapter(new MyBaseAdapter(mGridviewDatas, R.layout.gridview_item, getContext()) {
58 |
59 | @Override
60 | protected void convert(ViewHolder viewHolder, String t) {
61 | viewHolder.setBtnText(R.id.item_text, t);
62 | }
63 | });
64 | /**每一个子项回调给监听者*/
65 | mGridView.setOnItemClickListener(new OnItemClickListener() {
66 |
67 | @Override
68 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
69 | if(mOnExpandItemClick != null)
70 | {
71 | mOnExpandItemClick.onItemClick(position);
72 | }
73 | }
74 | });
75 | /**底部按钮的回调*/
76 | mBottomBtn.setOnClickListener(new OnClickListener() {
77 |
78 | @Override
79 | public void onClick(View v) {
80 | if(mOnExpandItemClick != null)
81 | {
82 | mOnExpandItemClick.onBottomClick();
83 | }
84 | }
85 | });
86 | }
87 |
88 | public String getTitle() {
89 | return mTitle == null ? new String() : mTitle;
90 | }
91 |
92 | public void setTitle(String mTitle) {
93 | this.mTitle = mTitle;
94 | }
95 |
96 | public List getmGridviewDatas() {
97 | return mGridviewDatas == null ? new ArrayList() : mGridviewDatas;
98 | }
99 |
100 | public void setmGridviewDatas(List mGridviewDatas) {
101 | this.mGridviewDatas = mGridviewDatas;
102 | }
103 |
104 | /**
105 | * 累加子类的高度作为自身的高度
106 | */
107 | @Override
108 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
109 | int cCount = getChildCount();
110 |
111 | int desireWidth = MeasureSpec.getSize(widthMeasureSpec);
112 | int desireHeight = 0;
113 | for (int i = 0; i < cCount; i++) {
114 | View child = getChildAt(i);
115 | measureChild(child, widthMeasureSpec, heightMeasureSpec);
116 | desireHeight += child.getMeasuredHeight();
117 | }
118 | setMeasuredDimension(desireWidth, desireHeight);
119 | }
120 |
121 | /**
122 | * 点击item事件回调给监听者
123 | * @author rander
124 | */
125 | public interface OnExpandItemClick
126 | {
127 | void onItemClick(int position);
128 | void onBottomClick();
129 | }
130 |
131 | private OnExpandItemClick mOnExpandItemClick;
132 |
133 | public void setOnExpandItemClick(OnExpandItemClick onExpandItemClick) {
134 | this.mOnExpandItemClick = onExpandItemClick;
135 | }
136 |
137 |
138 |
139 | }
140 |
--------------------------------------------------------------------------------
/src/com/example/expandableview/ExpandableView.java:
--------------------------------------------------------------------------------
1 | package com.example.expandableview;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.example.expandableview.ExpandleItemView.OnExpandItemClick;
7 |
8 | import android.content.Context;
9 | import android.graphics.Color;
10 | import android.graphics.drawable.BitmapDrawable;
11 | import android.util.AttributeSet;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.widget.LinearLayout;
15 | import android.widget.PopupWindow;
16 | import android.widget.PopupWindow.OnDismissListener;
17 | import android.widget.RelativeLayout;
18 | import android.widget.ToggleButton;
19 |
20 | public class ExpandableView extends LinearLayout implements OnExpandItemClick {
21 | /** 记录选中的ToggleButton */
22 | private ToggleButton mSelectToggleBtn;
23 | /** 筛选 */
24 | private List mToggleButtons = new ArrayList<>();
25 | /** 筛选项集合 */
26 | private List mPopupviews;
27 |
28 | /** popupwindow展示的宽 */
29 | private int mDisplayWidth;
30 | /** popupwindow展示的高 */
31 | private int mDisplayHeight;
32 | /** 筛选内容用PopupWindow弹出来 */
33 | private PopupWindow mPopupWindow;
34 | private Context mContext;
35 |
36 | /** toggleButton正常的字体颜色 */
37 | int mNormalTextColor = getResources().getColor(R.color.grey);
38 | /** toggleButton被选中的类型字体颜色 */
39 | int mSelectTextColor = Color.RED;
40 |
41 | public ExpandableView(Context context, AttributeSet attrs, int defStyleAttr) {
42 | super(context, attrs, defStyleAttr);
43 | init();
44 | }
45 |
46 | public ExpandableView(Context context, AttributeSet attrs) {
47 | this(context, attrs, -1);
48 | }
49 |
50 | public ExpandableView(Context context) {
51 | this(context, null);
52 | }
53 |
54 | private void init() {
55 | setOrientation(LinearLayout.HORIZONTAL);
56 | mDisplayWidth = getResources().getDisplayMetrics().widthPixels;
57 | mDisplayHeight = getResources().getDisplayMetrics().heightPixels;
58 | mContext = getContext();
59 | setBackgroundResource(R.drawable.choosearea_bg_right);
60 | }
61 |
62 | /**
63 | * 初始化数据和布局,做的工作如下: 1.根据筛选项的数量,动态增加上面一排ToggleButton 2.设置每一个ToggleButton的监听事件
64 | * 3.toggleButton.setTag(i)这一句非常重要,我们取View数据都是根据这个tag取的 4.
65 | *
66 | * @param views
67 | */
68 | public void initViews(List views) {
69 | mPopupviews = new ArrayList<>();
70 | LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
71 | for (int i = 0; i < views.size(); i++) {
72 | ExpandleItemView view = views.get(i);
73 | view.setOnExpandItemClick(this);
74 | final RelativeLayout r = new RelativeLayout(mContext);
75 | RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
76 | RelativeLayout.LayoutParams.WRAP_CONTENT);
77 | r.addView(view, rl);
78 | mPopupviews.add(r);
79 |
80 | final ToggleButton toggleButton = (ToggleButton) inflater.inflate(R.layout.toggle_button, this, false);
81 | toggleButton.setText(view.getTitle());
82 | mToggleButtons.add(toggleButton);
83 | addView(toggleButton);
84 | toggleButton.setTag(i);
85 | toggleButton.setOnClickListener(new OnClickListener() {
86 |
87 | @Override
88 | public void onClick(View v) {
89 | /** 记录选中的ToggleButton,有了这个什么都好办 */
90 | mSelectToggleBtn = toggleButton;
91 | showPopWindow();
92 | }
93 | });
94 | /**
95 | * 点击popupwindow外部,就隐藏popupwindow,这个r是点击事件包裹了一个ExpandleItemView
96 | * 如果用户所点之处为ExpandleItemView所在范围,点击事件由ExpandleItemView,如果点到
97 | * ExpandleItemView外面,则有r处理,处理方式就是收缩
98 | */
99 | r.setOnClickListener(new OnClickListener() {
100 |
101 | @Override
102 | public void onClick(View v) {
103 | onPressBack();
104 | }
105 |
106 | private void onPressBack() {
107 | hidePopWindow();
108 | }
109 | });
110 | }
111 | }
112 |
113 | /**
114 | * 隐藏popupWindow,并且重置ToggleButton字体颜色
115 | */
116 | private void hidePopWindow() {
117 | if (mPopupWindow != null) {
118 | mPopupWindow.dismiss();
119 | }
120 | if (mSelectToggleBtn != null) {
121 | mSelectToggleBtn.setTextColor(mNormalTextColor);
122 | mSelectToggleBtn.setChecked(false);
123 | }
124 | }
125 |
126 | /**
127 | * 显示popupWindow
128 | */
129 | private void showPopWindow() {
130 | if (null == mPopupWindow) {
131 | mPopupWindow = new PopupWindow(mPopupviews.get((int) mSelectToggleBtn.getTag()), mDisplayWidth,
132 | mDisplayHeight);
133 | /** 监听popupWindow的收缩,并重置字体颜色 */
134 | mPopupWindow.setOnDismissListener(new OnDismissListener() {
135 |
136 | @Override
137 | public void onDismiss() {
138 | if (mSelectToggleBtn != null) {
139 | mSelectToggleBtn.setTextColor(mNormalTextColor);
140 | mSelectToggleBtn.setChecked(false);
141 | }
142 | }
143 | });
144 | mPopupWindow.setAnimationStyle(R.style.PopupWindowAnimation);
145 | mPopupWindow.setFocusable(true);
146 | mPopupWindow.setOutsideTouchable(true);
147 | mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
148 | } else {
149 | mPopupWindow.setContentView(mPopupviews.get((int) mSelectToggleBtn.getTag()));
150 | }
151 |
152 | if (mPopupWindow.isShowing()) {
153 | hidePopWindow();
154 | } else {
155 | /** 显示的时候,设为选中颜色 */
156 | mSelectToggleBtn.setTextColor(mSelectTextColor);
157 | mPopupWindow.showAsDropDown(mToggleButtons.get(0), 0, 0);
158 | }
159 | }
160 |
161 | /**
162 | * Item项选中的回调 注意Tag的使用 筛选项视图是根据tag拿的,因为mSelectToggleBtn的tag就是视图的索引
163 | * mSelectToggleBtn显示筛选的内容
164 | */
165 | @Override
166 | public void onItemClick(int position) {
167 | hidePopWindow();
168 | if (null != mSelectToggleBtn) {
169 | int selectBtnIndex = (int) mSelectToggleBtn.getTag();
170 | mSelectToggleBtn
171 | .setText(((ExpandleItemView) (((RelativeLayout) mPopupviews.get(selectBtnIndex)).getChildAt(0)))
172 | .getmGridviewDatas().get(position));
173 | }
174 | }
175 |
176 | /**
177 | * 底部按钮点击的回调 mSelectToggleBtn显示筛选的内容
178 | */
179 | @Override
180 | public void onBottomClick() {
181 | hidePopWindow();
182 | if (null != mSelectToggleBtn) {
183 | int selectBtnIndex = (int) mSelectToggleBtn.getTag();
184 | mSelectToggleBtn
185 | .setText((((ExpandleItemView) (((RelativeLayout) mPopupviews.get(selectBtnIndex)).getChildAt(0)))
186 | .getTitle()));
187 | }
188 | }
189 | }
190 |
--------------------------------------------------------------------------------