├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── libs │ ├── butterknife-7.0.1.jar │ └── universal-image-loader-1.9.3-with-sources.jar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── voids │ │ └── ben │ │ └── searchexpandtabview │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── voids │ │ │ └── ben │ │ │ └── searchexpandtabview │ │ │ ├── MainActivity.java │ │ │ ├── adapter │ │ │ ├── SearchItemAdapter.java │ │ │ ├── SearchSysParamAdapter.java │ │ │ └── StaggeredAdapter.java │ │ │ ├── bean │ │ │ ├── AreaBean.java │ │ │ └── SysParamsBean.java │ │ │ ├── expandtabview │ │ │ ├── DividerItemDecoration.java │ │ │ ├── SearchTabLeft.java │ │ │ ├── SearchTabMiddle.java │ │ │ ├── SearchTabRight.java │ │ │ ├── SearchTabView.java │ │ │ └── ViewBaseAction.java │ │ │ └── mApplication.java │ └── res │ │ ├── anim │ │ ├── pophidden_anim.xml │ │ └── popshow_anim.xml │ │ ├── drawable │ │ ├── bg_edit.xml │ │ ├── search_choose_item_selector.xml │ │ ├── selector_expand_tab.xml │ │ └── selector_searchtab_text.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── btn_taggle_search.xml │ │ ├── item_staggered.xml │ │ ├── line.xml │ │ ├── search_choose_item.xml │ │ ├── search_double_item.xml │ │ └── search_single_item.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ ├── device-2016-05-1-180238.png │ │ ├── device-2016-05-1-180343.png │ │ ├── ic_collapse.png │ │ ├── ic_expanded.png │ │ ├── ic_launcher.png │ │ ├── pic1.jpg │ │ ├── pic2.jpeg │ │ ├── pic3.png │ │ ├── pic4.jpg │ │ ├── pic5.jpg │ │ └── pic6.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── voids │ └── ben │ └── searchexpandtabview │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | SearchExpandTabView -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Android Lint 39 | 40 | 41 | Error handlingJava 42 | 43 | 44 | General 45 | 46 | 47 | Java 48 | 49 | 50 | Manifest 51 | 52 | 53 | Portability issuesJava 54 | 55 | 56 | Properties Files 57 | 58 | 59 | 60 | 61 | Android 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 83 | 84 | 86 | 87 | 88 | 89 | 90 | 1.7 91 | 92 | 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SearchExpandTabView 2 | 仿美团多级下拉列表菜单,借鉴参考链接http://www.2cto.com/kf/201409/336647.html 3 | recyclerview+swiperefreshlayout基本实现下拉刷新,瀑布流显示,长按进行动态删除 4 | ## one 5 | ![image](https://github.com/intBen/SearchExpandTabView/blob/master/app/src/main/res/mipmap-xhdpi/device-2016-05-1-180238.png) 6 | ## two 7 | ![image](https://github.com/intBen/SearchExpandTabView/blob/master/app/src/main/res/mipmap-xhdpi/device-2016-05-1-180343.png) 8 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.voids.ben.searchexpandtabview" 9 | minSdkVersion 15 10 | targetSdkVersion 22 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:22.0.0' 26 | compile 'com.android.support:recyclerview-v7:22.0.0' 27 | compile files('libs/universal-image-loader-1.9.3-with-sources.jar') 28 | } 29 | -------------------------------------------------------------------------------- /app/libs/butterknife-7.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intBen/SearchExpandTabView/c90f5ba751f0466e53fa4d476dbbc13f2a7916d3/app/libs/butterknife-7.0.1.jar -------------------------------------------------------------------------------- /app/libs/universal-image-loader-1.9.3-with-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intBen/SearchExpandTabView/c90f5ba751f0466e53fa4d476dbbc13f2a7916d3/app/libs/universal-image-loader-1.9.3-with-sources.jar -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/ben/Documents/android-sdk-macosx/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/voids/ben/searchexpandtabview/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.voids.ben.searchexpandtabview; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/voids/ben/searchexpandtabview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.voids.ben.searchexpandtabview; 2 | 3 | import android.app.Activity; 4 | import android.app.Dialog; 5 | import android.os.Bundle; 6 | import android.os.Handler; 7 | import android.support.v4.widget.SwipeRefreshLayout; 8 | import android.support.v7.widget.DefaultItemAnimator; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.support.v7.widget.StaggeredGridLayoutManager; 11 | import android.util.Log; 12 | import android.view.View; 13 | import android.widget.Button; 14 | import android.widget.EditText; 15 | import android.widget.Toast; 16 | 17 | import com.voids.ben.searchexpandtabview.adapter.StaggeredAdapter; 18 | import com.voids.ben.searchexpandtabview.expandtabview.DividerItemDecoration; 19 | import com.voids.ben.searchexpandtabview.expandtabview.SearchTabLeft; 20 | import com.voids.ben.searchexpandtabview.expandtabview.SearchTabMiddle; 21 | import com.voids.ben.searchexpandtabview.expandtabview.SearchTabRight; 22 | import com.voids.ben.searchexpandtabview.expandtabview.SearchTabView; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | import butterknife.Bind; 28 | import butterknife.ButterKnife; 29 | 30 | public class MainActivity extends Activity { 31 | 32 | @Bind(android.R.id.list) 33 | RecyclerView rvSomething; 34 | @Bind(R.id.swipe_refresh_widget) 35 | SwipeRefreshLayout swipeRefreshWidget; 36 | @Bind(R.id.search_title) 37 | EditText searchTitle; 38 | @Bind(R.id.btn_search) 39 | Button btnSearch; 40 | @Bind(R.id.expandtab_view) 41 | SearchTabView expandtabView; 42 | 43 | private StaggeredAdapter mStaggeredAdapter; 44 | 45 | private ArrayList mViewArray = new ArrayList(); 46 | private SearchTabLeft viewLeft; 47 | private SearchTabMiddle viewMiddle; 48 | private SearchTabRight viewRight; 49 | private String SearchContent; 50 | private List mPics; 51 | 52 | 53 | private String longitude; 54 | private String latitude; 55 | private String districtcode; 56 | private String rank; 57 | private String specialty; 58 | 59 | private Dialog dialog; 60 | 61 | @Override 62 | protected void onCreate(Bundle savedInstanceState) { 63 | super.onCreate(savedInstanceState); 64 | setContentView(R.layout.activity_main); 65 | ButterKnife.bind(this); 66 | initView(); 67 | initData(); 68 | initListener(); 69 | } 70 | 71 | private void initData() { 72 | // tab设置 73 | mViewArray.add(viewLeft); 74 | mViewArray.add(viewMiddle); 75 | mViewArray.add(viewRight); 76 | 77 | mPics=new ArrayList(); 78 | for (int i = 0; i < 15; i++) { 79 | if (i == 2 || i == 4 || i == 5 || i == 8 || i == 10) { 80 | mPics.add(""); 81 | } else { 82 | mPics.add("https://www.eff.org/sites/default/files/chrome150_0.jpg"); 83 | } 84 | } 85 | mStaggeredAdapter = new StaggeredAdapter(this, mPics); 86 | rvSomething.setLayoutManager(new StaggeredGridLayoutManager(2, 87 | StaggeredGridLayoutManager.VERTICAL)); 88 | rvSomething.setAdapter(mStaggeredAdapter); 89 | // 设置item动画 90 | rvSomething.setItemAnimator(new DefaultItemAnimator()); 91 | rvSomething.addItemDecoration(new DividerItemDecoration(this, 92 | DividerItemDecoration.VERTICAL_LIST)); 93 | rvSomething.addItemDecoration(new DividerItemDecoration(this, 94 | DividerItemDecoration.HORIZONTAL_LIST)); 95 | initEvent(); 96 | 97 | ArrayList mTextArray = new ArrayList(); 98 | mTextArray.add(getResources().getString(R.string.region_serach_title)); 99 | mTextArray.add(getResources().getString(R.string.rank_serach_title)); 100 | mTextArray.add(getResources().getString(R.string.specialty_serach_title)); 101 | expandtabView.setValue(mTextArray, mViewArray); 102 | expandtabView.setTitle(mTextArray.get(0), 0); 103 | expandtabView.setTitle(mTextArray.get(1), 1); 104 | expandtabView.setTitle(mTextArray.get(2), 2); 105 | 106 | } 107 | 108 | private void initView() { 109 | 110 | viewLeft = new SearchTabLeft(this); 111 | viewMiddle = new SearchTabMiddle(this); 112 | viewRight = new SearchTabRight(this); 113 | swipeRefreshWidget.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 114 | @Override 115 | public void onRefresh() { 116 | swipeRefreshWidget.setRefreshing(true); 117 | Log.d("Swipe", "Refreshing Number"); 118 | (new Handler()).postDelayed(new Runnable() { 119 | 120 | @Override 121 | public void run() { 122 | swipeRefreshWidget.setRefreshing(false); 123 | Toast.makeText(MainActivity.this, "刷新成功", Toast.LENGTH_SHORT).show(); 124 | } 125 | }, 3000); 126 | } 127 | }); 128 | 129 | 130 | } 131 | 132 | 133 | private void initEvent() 134 | { 135 | mStaggeredAdapter.setOnItemClickLitener(new StaggeredAdapter.OnItemClickLitener() { 136 | @Override 137 | public void onItemClick(View view, int position) { 138 | Toast.makeText(MainActivity.this, 139 | position + " click", Toast.LENGTH_SHORT).show(); 140 | } 141 | 142 | @Override 143 | public void onItemLongClick(View view, int position) { 144 | Toast.makeText(MainActivity.this, 145 | position + " long click", Toast.LENGTH_SHORT).show(); 146 | } 147 | }); 148 | } 149 | 150 | /** 151 | * @Description: expandTab 监听 152 | * @Author:胡帅 153 | * @Since: 2016年4月13日下午2:51:20 154 | */ 155 | private void initListener() { 156 | 157 | viewLeft.setOnSelectListener(new SearchTabLeft.OnSelectListener() { 158 | 159 | @Override 160 | public void getValue(String itemCode, String showText) { 161 | districtcode = itemCode; 162 | onRefresh(viewLeft, showText); 163 | } 164 | }); 165 | 166 | viewMiddle.setOnSelectListener(new SearchTabMiddle.OnSelectListener() { 167 | 168 | @Override 169 | public void getValue(String itemLvTwocode, String showText) { 170 | 171 | rank = itemLvTwocode; 172 | onRefresh(viewMiddle, showText); 173 | 174 | } 175 | }); 176 | 177 | viewRight.setOnSelectListener(new SearchTabRight.OnSelectListener() { 178 | 179 | @Override 180 | public void getValue(String itemCode, String showText) { 181 | 182 | specialty = itemCode; 183 | onRefresh(viewRight, showText); 184 | } 185 | }); 186 | 187 | } 188 | 189 | /** 190 | * @param view 191 | * @param showText 192 | * @Description: 回调更新选中项 193 | * @Author:胡帅 194 | * @Since: 2016年4月13日下午2:52:04 195 | */ 196 | private void onRefresh(View view, String showText) { 197 | 198 | expandtabView.onPressBack(); 199 | int position = getPositon(view); 200 | if (position >= 0 && !expandtabView.getTitle(position).equals(showText)) { 201 | expandtabView.setTitle(showText, position); 202 | } 203 | Toast.makeText(MainActivity.this, showText, Toast.LENGTH_SHORT).show(); 204 | 205 | 206 | } 207 | 208 | private int getPositon(View tView) { 209 | for (int i = 0; i < mViewArray.size(); i++) { 210 | if (mViewArray.get(i) == tView) { 211 | return i; 212 | } 213 | } 214 | return -1; 215 | } 216 | 217 | @Override 218 | public void onBackPressed() { 219 | 220 | if (!expandtabView.onPressBack()) { 221 | finish(); 222 | } 223 | 224 | } 225 | 226 | 227 | } 228 | -------------------------------------------------------------------------------- /app/src/main/java/com/voids/ben/searchexpandtabview/adapter/SearchItemAdapter.java: -------------------------------------------------------------------------------- 1 | package com.voids.ben.searchexpandtabview.adapter; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.Drawable; 5 | import android.util.TypedValue; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.View.OnClickListener; 9 | import android.view.ViewGroup; 10 | import android.widget.ArrayAdapter; 11 | import android.widget.TextView; 12 | 13 | import com.voids.ben.searchexpandtabview.R; 14 | import com.voids.ben.searchexpandtabview.bean.AreaBean; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | *@Description:适配器 控制选中状态 可设置选中图片 20 | *@Author:胡帅 21 | *@Since:2016年4月13日下午1:28:37 22 | */ 23 | public class SearchItemAdapter extends ArrayAdapter { 24 | 25 | private Context mContext; 26 | private List mListData; 27 | private String[] mArrayData; 28 | private int selectedPos = -1; 29 | private String selectedText = ""; 30 | private int normalDrawbleId; 31 | private Drawable selectedDrawble; 32 | private float textSize; 33 | private OnClickListener onClickListener; 34 | private OnItemClickListener mOnItemClickListener; 35 | private int mSelectType = 0; // 0=father 1=son 36 | 37 | /** 38 | *Description: searchtab 构造器 可以自定义样式 39 | * @param context 40 | * @param listData 41 | * @param sId 选中bg id 42 | * @param nId 选择bg id e.g 打勾样式 43 | * @param type 44 | */ 45 | public SearchItemAdapter(Context context, List listData, int sId, int nId, int type) { 46 | super (context, R.string.no_data, listData); 47 | mContext = context; 48 | mListData = listData; 49 | mSelectType = type; 50 | // selectedDrawble = mContext.getResources().getDrawable(sId); 51 | // normalDrawbleId = nId; 52 | 53 | init (); 54 | } 55 | 56 | private void init(){ 57 | onClickListener = new OnClickListener () { 58 | 59 | @Override 60 | public void onClick(View view){ 61 | selectedPos = (Integer) view.getTag (); 62 | setSelectedPosition (selectedPos); 63 | if (mOnItemClickListener != null) { 64 | mOnItemClickListener.onItemClick (view, selectedPos); 65 | } 66 | } 67 | }; 68 | } 69 | 70 | /** 71 | * 设置选中的position,并通知列表刷新 72 | */ 73 | public void setSelectedPosition(int pos){ 74 | if (mListData != null && pos < mListData.size ()) { 75 | selectedPos = pos; 76 | selectedText = mListData.get (pos).getAreaName (); 77 | notifyDataSetChanged (); 78 | } 79 | // else if (mArrayData != null && pos < mArrayData.length) { 80 | // selectedPos = pos; 81 | // selectedText = mArrayData[pos]; 82 | // notifyDataSetChanged(); 83 | // } 84 | 85 | } 86 | 87 | /** 88 | * 设置选中的position,但不通知刷新 89 | */ 90 | public void setSelectedPositionNoNotify(int pos){ 91 | selectedPos = pos; 92 | if (mListData != null && pos < mListData.size ()) { 93 | selectedText = mListData.get (pos).getAreaName (); 94 | } 95 | // else if (mArrayData != null && pos < mArrayData.length) { 96 | // selectedText = mArrayData[pos]; 97 | // } 98 | } 99 | 100 | /** 101 | * 获取选中的position 102 | */ 103 | public int getSelectedPosition(){ 104 | if (mArrayData != null && selectedPos < mArrayData.length) { return selectedPos; } 105 | if (mListData != null && selectedPos < mListData.size ()) { return selectedPos; } 106 | 107 | return -1; 108 | } 109 | 110 | /** 111 | * 设置列表字体大小 112 | */ 113 | public void setTextSize(float tSize){ 114 | textSize = tSize; 115 | } 116 | 117 | @Override 118 | public View getView(int position,View convertView,ViewGroup parent){ 119 | TextView view; 120 | if (convertView == null) { 121 | view = (TextView) LayoutInflater.from (mContext).inflate (R.layout.search_choose_item, parent, false); 122 | } else { 123 | view = (TextView) convertView; 124 | } 125 | view.setTag (position); 126 | String mString = ""; 127 | if (mListData != null) { 128 | if (position < mListData.size ()) { 129 | mString = mListData.get (position).getAreaName (); 130 | } 131 | } 132 | // else if (mArrayData != null) { 133 | // if (position < mArrayData.length) { 134 | // mString = mArrayData[position]; 135 | // } 136 | // } 137 | if (mString.contains ("不限")) view.setText ("不限"); 138 | else view.setText (mString); 139 | view.setTextSize (TypedValue.COMPLEX_UNIT_SP, textSize); 140 | 141 | if (selectedText != null && selectedText.equals (mString)) { 142 | view.setBackgroundColor (mContext.getResources ().getColor (R.color.text_hint)); 143 | view.setTextColor (mContext.getResources ().getColor (R.color.text_blue)); 144 | // view.setBackgroundDrawable(selectedDrawble);//设置选中的背景图片 145 | } else { 146 | 147 | view.setTextColor (mContext.getResources ().getColor (R.color.text_black)); 148 | if (mSelectType == 0) { 149 | view.setBackgroundColor (mContext.getResources ().getColor (R.color.white)); 150 | } else { 151 | view.setBackgroundColor (mContext.getResources ().getColor (R.color.text_hint)); 152 | } 153 | 154 | // view.setBackgroundDrawable(mContext.getResources().getDrawable(normalDrawbleId));//设置未选中状态背景图片 155 | } 156 | view.setPadding (20, 0, 0, 0); 157 | view.setOnClickListener (onClickListener); 158 | return view; 159 | } 160 | 161 | public void setOnItemClickListener(OnItemClickListener l){ 162 | mOnItemClickListener = l; 163 | } 164 | 165 | /** 166 | * 重新定义菜单选项单击接口 167 | */ 168 | public interface OnItemClickListener { 169 | 170 | public void onItemClick(View view,int position); 171 | } 172 | 173 | } 174 | -------------------------------------------------------------------------------- /app/src/main/java/com/voids/ben/searchexpandtabview/adapter/SearchSysParamAdapter.java: -------------------------------------------------------------------------------- 1 | package com.voids.ben.searchexpandtabview.adapter; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.Drawable; 5 | import android.util.TypedValue; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.View.OnClickListener; 9 | import android.view.ViewGroup; 10 | import android.widget.ArrayAdapter; 11 | import android.widget.TextView; 12 | 13 | import com.voids.ben.searchexpandtabview.R; 14 | import com.voids.ben.searchexpandtabview.bean.SysParamsBean; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | *@Description:适配器 控制选中状态 可设置选中图片 20 | *@Author:胡帅 21 | *@Since:2016年4月13日下午1:28:37 22 | */ 23 | public class SearchSysParamAdapter extends ArrayAdapter { 24 | 25 | private Context mContext; 26 | private List mListData; 27 | private String[] mArrayData; 28 | private int selectedPos = -1; 29 | private String selectedText = ""; 30 | private int normalDrawbleId; 31 | private Drawable selectedDrawble; 32 | private float textSize; 33 | private OnClickListener onClickListener; 34 | private OnItemClickListener mOnItemClickListener; 35 | private int mSelectType = 0; // 0=father 1=son 36 | 37 | /** 38 | *Description: searchtab 构造器 可以自定义样式 39 | * @param context 40 | * @param listData 41 | * @param sId 选中bg id 42 | * @param nId 选择bg id e.g 打勾样式 43 | * @param type 44 | */ 45 | public SearchSysParamAdapter(Context context, List listData, int sId, int nId, int type) { 46 | super (context, R.string.no_data, listData); 47 | mContext = context; 48 | mListData = listData; 49 | mSelectType = type; 50 | // selectedDrawble = mContext.getResources().getDrawable(sId); 51 | // normalDrawbleId = nId; 52 | 53 | init (); 54 | } 55 | 56 | private void init(){ 57 | onClickListener = new OnClickListener () { 58 | 59 | @Override 60 | public void onClick(View view){ 61 | selectedPos = (Integer) view.getTag (); 62 | setSelectedPosition (selectedPos); 63 | if (mOnItemClickListener != null) { 64 | mOnItemClickListener.onItemClick (view, selectedPos); 65 | } 66 | } 67 | }; 68 | } 69 | 70 | /** 71 | * 设置选中的position,并通知列表刷新 72 | */ 73 | public void setSelectedPosition(int pos){ 74 | if (mListData != null && pos < mListData.size ()) { 75 | selectedPos = pos; 76 | selectedText = mListData.get (pos).getParName(); 77 | notifyDataSetChanged (); 78 | } 79 | // else if (mArrayData != null && pos < mArrayData.length) { 80 | // selectedPos = pos; 81 | // selectedText = mArrayData[pos]; 82 | // notifyDataSetChanged(); 83 | // } 84 | 85 | } 86 | 87 | /** 88 | * 设置选中的position,但不通知刷新 89 | */ 90 | public void setSelectedPositionNoNotify(int pos){ 91 | selectedPos = pos; 92 | if (mListData != null && pos < mListData.size ()) { 93 | selectedText = mListData.get (pos).getParName (); 94 | } 95 | // else if (mArrayData != null && pos < mArrayData.length) { 96 | // selectedText = mArrayData[pos]; 97 | // } 98 | } 99 | 100 | /** 101 | * 获取选中的position 102 | */ 103 | public int getSelectedPosition(){ 104 | if (mArrayData != null && selectedPos < mArrayData.length) { return selectedPos; } 105 | if (mListData != null && selectedPos < mListData.size ()) { return selectedPos; } 106 | 107 | return -1; 108 | } 109 | 110 | /** 111 | * 设置列表字体大小 112 | */ 113 | public void setTextSize(float tSize){ 114 | textSize = tSize; 115 | } 116 | 117 | @Override 118 | public View getView(int position,View convertView,ViewGroup parent){ 119 | TextView view; 120 | if (convertView == null) { 121 | view = (TextView) LayoutInflater.from (mContext).inflate (R.layout.search_choose_item, parent, false); 122 | } else { 123 | view = (TextView) convertView; 124 | } 125 | view.setTag (position); 126 | String mString = ""; 127 | if (mListData != null) { 128 | if (position < mListData.size ()) { 129 | mString = mListData.get (position).getParName (); 130 | } 131 | } 132 | // else if (mArrayData != null) { 133 | // if (position < mArrayData.length) { 134 | // mString = mArrayData[position]; 135 | // } 136 | // } 137 | if (mString.contains ("不限")) view.setText ("不限"); 138 | else view.setText (mString); 139 | view.setTextSize (TypedValue.COMPLEX_UNIT_SP, textSize); 140 | 141 | if (selectedText != null && selectedText.equals (mString)) { 142 | view.setBackgroundColor (mContext.getResources ().getColor (R.color.text_hint)); 143 | view.setTextColor (mContext.getResources ().getColor (R.color.text_blue)); 144 | // view.setBackgroundDrawable(selectedDrawble);//设置选中的背景图片 145 | } else { 146 | 147 | view.setTextColor (mContext.getResources ().getColor (R.color.text_black)); 148 | if (mSelectType == 0) { 149 | view.setBackgroundColor (mContext.getResources ().getColor (R.color.white)); 150 | } else { 151 | view.setBackgroundColor (mContext.getResources ().getColor (R.color.text_hint)); 152 | } 153 | 154 | // view.setBackgroundDrawable(mContext.getResources().getDrawable(normalDrawbleId));//设置未选中状态背景图片 155 | } 156 | view.setPadding (20, 0, 0, 0); 157 | view.setOnClickListener (onClickListener); 158 | return view; 159 | } 160 | 161 | public void setOnItemClickListener(OnItemClickListener l){ 162 | mOnItemClickListener = l; 163 | } 164 | 165 | /** 166 | * 重新定义菜单选项单击接口 167 | */ 168 | public interface OnItemClickListener { 169 | 170 | public void onItemClick(View view,int position); 171 | } 172 | 173 | } 174 | 175 | -------------------------------------------------------------------------------- /app/src/main/java/com/voids/ben/searchexpandtabview/adapter/StaggeredAdapter.java: -------------------------------------------------------------------------------- 1 | package com.voids.ben.searchexpandtabview.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import com.nostra13.universalimageloader.core.ImageLoader; 12 | import com.voids.ben.searchexpandtabview.R; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | /** 18 | * Created by ben on 16/5/17. 19 | */ 20 | public class StaggeredAdapter extends 21 | RecyclerView.Adapter { 22 | 23 | private List mDatas; 24 | private LayoutInflater mInflater; 25 | private ImageLoader mImageLoader; 26 | 27 | private List mHeights; 28 | 29 | public interface OnItemClickLitener { 30 | void onItemClick(View view, int position); 31 | 32 | void onItemLongClick(View view, int position); 33 | } 34 | 35 | private OnItemClickLitener mOnItemClickLitener; 36 | 37 | public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) { 38 | this.mOnItemClickLitener = mOnItemClickLitener; 39 | } 40 | 41 | public StaggeredAdapter(Context context, List datas) { 42 | mInflater = LayoutInflater.from(context); 43 | mDatas = datas; 44 | 45 | mHeights = new ArrayList(); 46 | for (int i = 0; i < mDatas.size(); i++) { 47 | mHeights.add((int) (100 + Math.random() * 300)); 48 | } 49 | } 50 | 51 | @Override 52 | public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 53 | MyViewHolder holder = new MyViewHolder(mInflater.inflate( 54 | R.layout.item_staggered, parent, false)); 55 | return holder; 56 | } 57 | 58 | @Override 59 | public void onBindViewHolder(final MyViewHolder holder, final int position) { 60 | ViewGroup.LayoutParams lp = holder.tv.getLayoutParams(); 61 | lp.height = mHeights.get(position); 62 | 63 | holder.tv.setLayoutParams(lp); 64 | holder.tv.setText(position + ""); 65 | ImageLoader.getInstance().displayImage(mDatas.get(position),holder.iv); 66 | 67 | // 如果设置了回调,则设置点击事件 68 | if (mOnItemClickLitener != null) { 69 | holder.itemView.setOnClickListener(new View.OnClickListener() { 70 | @Override 71 | public void onClick(View v) { 72 | int pos = holder.getLayoutPosition(); 73 | mOnItemClickLitener.onItemClick(holder.itemView, pos); 74 | } 75 | }); 76 | 77 | holder.itemView.setOnLongClickListener(new View.OnLongClickListener() { 78 | @Override 79 | public boolean onLongClick(View v) { 80 | int pos = holder.getLayoutPosition(); 81 | mOnItemClickLitener.onItemLongClick(holder.itemView, pos); 82 | removeData(pos); 83 | return false; 84 | } 85 | }); 86 | } 87 | } 88 | 89 | @Override 90 | public int getItemCount() { 91 | return mDatas.size(); 92 | } 93 | 94 | public void addData(int position) { 95 | mDatas.add(position, "Insert One"); 96 | mHeights.add((int) (100 + Math.random() * 300)); 97 | notifyItemInserted(position); 98 | } 99 | 100 | public void removeData(int position) { 101 | mDatas.remove(position); 102 | notifyItemRemoved(position); 103 | } 104 | 105 | class MyViewHolder extends RecyclerView.ViewHolder { 106 | 107 | TextView tv; 108 | ImageView iv; 109 | 110 | public MyViewHolder(View view) { 111 | super(view); 112 | tv = (TextView) view.findViewById(R.id.id_num); 113 | iv=(ImageView)view.findViewById(R.id.iv_bg); 114 | 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /app/src/main/java/com/voids/ben/searchexpandtabview/bean/AreaBean.java: -------------------------------------------------------------------------------- 1 | package com.voids.ben.searchexpandtabview.bean; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | *@Description: 区划 7 | */ 8 | public class AreaBean implements Serializable { 9 | 10 | 11 | 12 | public static final String SELECT_ID = "select_id"; 13 | public static final String SELECT_NAME = "select_name"; 14 | 15 | private Long id; 16 | 17 | /** 18 | *@Fields areaId : 区 ID 19 | */ 20 | private String areaId; 21 | 22 | /** 23 | *@Fields areaName : 区 Name 24 | */ 25 | private String areaName; 26 | 27 | /** 28 | *@Fields pId : 区 Pid 29 | */ 30 | private String pid; 31 | 32 | 33 | private boolean checked; 34 | 35 | /** 36 | * @Fields 备注 37 | */ 38 | private String remark1; 39 | 40 | /** 41 | * @Fields 备注 42 | */ 43 | private String remark2; 44 | 45 | /** 46 | * @Fields 备注 47 | */ 48 | private String remark3; 49 | 50 | public Long getId(){ 51 | return id; 52 | } 53 | 54 | public void setId(Long id){ 55 | this.id = id; 56 | } 57 | 58 | public String getAreaId(){ 59 | return areaId; 60 | } 61 | 62 | public void setAreaId(String areaId){ 63 | this.areaId = areaId; 64 | } 65 | 66 | public String getAreaName(){ 67 | return areaName; 68 | } 69 | 70 | public void setAreaName(String areaName){ 71 | this.areaName = areaName; 72 | } 73 | 74 | public String getPid(){ 75 | return pid; 76 | } 77 | 78 | public void setPid(String pid){ 79 | this.pid = pid; 80 | } 81 | 82 | public boolean isChecked(){ 83 | return checked; 84 | } 85 | 86 | public void setChecked(boolean checked){ 87 | this.checked = checked; 88 | } 89 | 90 | public String getRemark1(){ 91 | return remark1; 92 | } 93 | 94 | public void setRemark1(String remark1){ 95 | this.remark1 = remark1; 96 | } 97 | 98 | public String getRemark2(){ 99 | return remark2; 100 | } 101 | 102 | public void setRemark2(String remark2){ 103 | this.remark2 = remark2; 104 | } 105 | 106 | public String getRemark3(){ 107 | return remark3; 108 | } 109 | 110 | public void setRemark3(String remark3){ 111 | this.remark3 = remark3; 112 | } 113 | 114 | @Override 115 | public boolean equals(Object o){ 116 | if (o == null) { 117 | return false; 118 | } else { 119 | if (this.getClass () == o.getClass ()) { 120 | AreaBean item = (AreaBean) o; 121 | if (this.getAreaId ().equals (item.getAreaId ())) { 122 | return true; 123 | } else { 124 | return false; 125 | } 126 | } else { 127 | return false; 128 | } 129 | } 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /app/src/main/java/com/voids/ben/searchexpandtabview/bean/SysParamsBean.java: -------------------------------------------------------------------------------- 1 | package com.voids.ben.searchexpandtabview.bean; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | *@Description: 参数表 7 | */ 8 | public class SysParamsBean implements Serializable { 9 | 10 | // 意图 IntentUtils 的参数key 11 | public static final String PARAMS_TYPE = "params_type"; 12 | public static final String PARAMS_ID = "params_id"; 13 | public static final String PARAMS_NAME = "params_name"; 14 | 15 | private Long id; 16 | 17 | /** 18 | *@Fields parCode : 参数 Code 19 | */ 20 | private String parCode; 21 | 22 | /** 23 | *@Fields parName : 参数名称 24 | */ 25 | private String parName; 26 | 27 | /** 28 | *@Fields pDicCode : 上级参数Code 29 | */ 30 | private String parParentCode; 31 | 32 | /** 33 | * @Fields 备注 34 | */ 35 | private String remark1; 36 | 37 | /** 38 | * @Fields 备注 39 | */ 40 | private String remark2; 41 | 42 | /** 43 | * @Fields 备注 44 | */ 45 | private String remark3; 46 | 47 | private boolean isChecked; 48 | 49 | public Long getId(){ 50 | return id; 51 | } 52 | 53 | public void setId(Long id){ 54 | this.id = id; 55 | } 56 | 57 | public String getParCode(){ 58 | return parCode; 59 | } 60 | 61 | public void setParCode(String parCode){ 62 | this.parCode = parCode; 63 | } 64 | 65 | public String getParName(){ 66 | return parName; 67 | } 68 | 69 | public void setParName(String parName){ 70 | this.parName = parName; 71 | } 72 | 73 | public String getParParentCode(){ 74 | return parParentCode; 75 | } 76 | 77 | public void setParParentCode(String parParentCode){ 78 | this.parParentCode = parParentCode; 79 | } 80 | 81 | public String getRemark1(){ 82 | return remark1; 83 | } 84 | 85 | public void setRemark1(String remark1){ 86 | this.remark1 = remark1; 87 | } 88 | 89 | public String getRemark2(){ 90 | return remark2; 91 | } 92 | 93 | public void setRemark2(String remark2){ 94 | this.remark2 = remark2; 95 | } 96 | 97 | public String getRemark3(){ 98 | return remark3; 99 | } 100 | 101 | public void setRemark3(String remark3){ 102 | this.remark3 = remark3; 103 | } 104 | 105 | 106 | 107 | 108 | public boolean isChecked(){ 109 | return isChecked; 110 | } 111 | 112 | 113 | public void setChecked(boolean isChecked){ 114 | this.isChecked = isChecked; 115 | } 116 | 117 | 118 | @Override 119 | public boolean equals(Object o){ 120 | if (o == null) { 121 | return false; 122 | } else { 123 | if (this.getClass () == o.getClass ()) { 124 | SysParamsBean sp = (SysParamsBean) o; 125 | if (this.getParCode ().equals (sp.getParCode ())) { 126 | return true; 127 | } else { 128 | return false; 129 | } 130 | } else { 131 | return false; 132 | } 133 | } 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /app/src/main/java/com/voids/ben/searchexpandtabview/expandtabview/DividerItemDecoration.java: -------------------------------------------------------------------------------- 1 | package com.voids.ben.searchexpandtabview.expandtabview; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Rect; 7 | import android.graphics.drawable.Drawable; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.view.View; 11 | 12 | /** 13 | * Created by ben on 16/5/1. 14 | * This class is from the v7 samples of the Android SDK.for diy 15 | */ 16 | public class DividerItemDecoration extends RecyclerView.ItemDecoration { 17 | 18 | private static final int[] ATTRS = new int[]{android.R.attr.listDivider}; 19 | 20 | public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL; 21 | 22 | public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL; 23 | 24 | 25 | private Drawable mDivider; 26 | 27 | private int mOrientation; 28 | 29 | public DividerItemDecoration(Context context, int orientation) { 30 | final TypedArray a = context.obtainStyledAttributes(ATTRS); 31 | mDivider = a.getDrawable(0); 32 | a.recycle(); 33 | setOrientation(orientation); 34 | } 35 | 36 | public void setOrientation(int orientation) { 37 | if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) { 38 | throw new IllegalArgumentException("invalid orientation"); 39 | } 40 | mOrientation = orientation; 41 | } 42 | 43 | @Override 44 | public void onDraw(Canvas c, RecyclerView parent) { 45 | 46 | if (mOrientation == VERTICAL_LIST) { 47 | drawVertical(c, parent); 48 | } else { 49 | drawHorizontal(c, parent); 50 | } 51 | } 52 | 53 | public void drawVertical(Canvas c, RecyclerView parent) { 54 | final int left = parent.getPaddingLeft(); 55 | final int right = parent.getWidth() - parent.getPaddingRight(); 56 | 57 | final int childCount = parent.getChildCount(); 58 | 59 | for (int i = 0; i < childCount; i++) { 60 | final View child = parent.getChildAt(i); 61 | android.support.v7.widget.RecyclerView v = new android.support.v7.widget.RecyclerView( 62 | parent.getContext()); 63 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child 64 | .getLayoutParams(); 65 | final int top = child.getBottom() + params.bottomMargin; 66 | final int bottom = top + mDivider.getIntrinsicHeight(); 67 | mDivider.setBounds(left, top, right, bottom); 68 | mDivider.draw(c); 69 | } 70 | } 71 | 72 | public void drawHorizontal(Canvas c, RecyclerView parent) { 73 | final int top = parent.getPaddingTop(); 74 | final int bottom = parent.getHeight() - parent.getPaddingBottom(); 75 | 76 | final int childCount = parent.getChildCount(); 77 | for (int i = 0; i < childCount; i++) { 78 | final View child = parent.getChildAt(i); 79 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child 80 | .getLayoutParams(); 81 | final int left = child.getRight() + params.rightMargin; 82 | final int right = left + mDivider.getIntrinsicHeight(); 83 | mDivider.setBounds(left, top, right, bottom); 84 | mDivider.draw(c); 85 | } 86 | } 87 | 88 | @Override 89 | public void getItemOffsets(Rect outRect, int itemPosition, 90 | RecyclerView parent) { 91 | if (mOrientation == VERTICAL_LIST) { 92 | outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); 93 | } else { 94 | outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /app/src/main/java/com/voids/ben/searchexpandtabview/expandtabview/SearchTabLeft.java: -------------------------------------------------------------------------------- 1 | package com.voids.ben.searchexpandtabview.expandtabview; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.widget.ListView; 8 | import android.widget.RelativeLayout; 9 | 10 | import com.voids.ben.searchexpandtabview.R; 11 | import com.voids.ben.searchexpandtabview.adapter.SearchItemAdapter; 12 | import com.voids.ben.searchexpandtabview.bean.AreaBean; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | /** 18 | *@Description:expandTab 左 地区item 19 | *@Author:ben 20 | *@Since:2016年4月13日下午2:31:58 21 | */ 22 | public class SearchTabLeft extends RelativeLayout implements ViewBaseAction { 23 | 24 | private ListView mListView; 25 | private List areaList; 26 | private final String[] items = new String[] { "全部地区", "item1", "item2", "item3", "item4", "item5", "item6" };// 显示字段 27 | private final String[] itemsVaule = new String[] { "1", "2", "3", "4", "5", "6", "7" }; // 隐藏id 28 | private OnSelectListener mOnSelectListener; 29 | private SearchItemAdapter adapter; 30 | private String mDistance; 31 | private String showText = "地区"; 32 | private Context mContext; 33 | private long selectId; 34 | 35 | public String getShowText(){ 36 | return showText; 37 | } 38 | 39 | public SearchTabLeft(Context context) { 40 | super (context); 41 | init (context); 42 | } 43 | 44 | public SearchTabLeft(Context context, AttributeSet attrs, int defStyle) { 45 | super (context, attrs, defStyle); 46 | init (context); 47 | } 48 | 49 | public SearchTabLeft(Context context, AttributeSet attrs) { 50 | super (context, attrs); 51 | init (context); 52 | } 53 | 54 | private void testData(){ 55 | areaList = new ArrayList (); 56 | AreaBean bean; 57 | for ( int i = 0 ; i < items.length ; i++ ) { 58 | bean = new AreaBean (); 59 | bean.setAreaName (items[i]); 60 | bean.setAreaId (""+i); 61 | areaList.add (bean); 62 | 63 | } 64 | } 65 | 66 | /** 67 | *@Description: 初始化视图 68 | *@Author:胡帅 69 | *@Since: 2016年4月13日下午4:30:58 70 | *@param context 71 | */ 72 | private void init(Context context){ 73 | 74 | 75 | mContext = context; 76 | LayoutInflater inflater = (LayoutInflater) context.getSystemService (Context.LAYOUT_INFLATER_SERVICE); 77 | inflater.inflate (R.layout.search_single_item, this, true); 78 | // setBackgroundDrawable(getResources().getDrawable(R.drawable.choosearea_bg_mid)); 79 | mListView = (ListView) findViewById (R.id.listViewSingle); 80 | 81 | // test 82 | testData(); 83 | 84 | adapter = new SearchItemAdapter (context,areaList,0,0,0); 85 | adapter.setSelectedPosition (0); 86 | adapter.setTextSize (17); 87 | if (selectId != 0) { 88 | for ( int i = 0 ; i < areaList.size () ; i++ ) { 89 | if (areaList.get (i).getId ()==selectId) { 90 | adapter.setSelectedPositionNoNotify (i); 91 | showText = areaList.get (i).getAreaName (); 92 | break; 93 | } 94 | } 95 | } 96 | 97 | mListView.setAdapter (adapter); 98 | adapter.setOnItemClickListener (new SearchItemAdapter.OnItemClickListener () { 99 | 100 | @Override 101 | public void onItemClick(View view,int position){ 102 | 103 | if (mOnSelectListener != null) { 104 | showText = areaList.get (position).getAreaName (); 105 | mOnSelectListener.getValue (areaList.get (position).getAreaId (), areaList.get (position).getAreaName ()); 106 | } 107 | } 108 | }); 109 | } 110 | 111 | public void setOnSelectListener(OnSelectListener onSelectListener){ 112 | mOnSelectListener = onSelectListener; 113 | } 114 | 115 | public interface OnSelectListener { 116 | 117 | public void getValue(String itemCode,String showText); 118 | } 119 | 120 | @Override 121 | public void hide(){ 122 | 123 | } 124 | 125 | @Override 126 | public void show(){ 127 | 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /app/src/main/java/com/voids/ben/searchexpandtabview/expandtabview/SearchTabMiddle.java: -------------------------------------------------------------------------------- 1 | package com.voids.ben.searchexpandtabview.expandtabview; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.util.SparseArray; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.widget.LinearLayout; 9 | import android.widget.ListView; 10 | 11 | import com.voids.ben.searchexpandtabview.R; 12 | import com.voids.ben.searchexpandtabview.adapter.SearchSysParamAdapter; 13 | import com.voids.ben.searchexpandtabview.bean.SysParamsBean; 14 | 15 | import java.util.ArrayList; 16 | import java.util.LinkedList; 17 | 18 | /** 19 | * @Description:expandTab 中间 星级item 20 | * @Author:ben 21 | * @Since:2016年4月13日下午2:32:59 22 | */ 23 | public class SearchTabMiddle extends LinearLayout implements ViewBaseAction { 24 | 25 | private ListView regionListView; 26 | private Context mContext; 27 | private ListView plateListView; 28 | private ArrayList groups = new ArrayList(); 29 | private LinkedList childrenItem = new LinkedList(); 30 | private SparseArray> children = new SparseArray>(); 31 | private SearchSysParamAdapter plateListViewAdapter; 32 | private SearchSysParamAdapter earaListViewAdapter; 33 | private OnSelectListener mOnSelectListener; 34 | private int tEaraPosition = 0; 35 | private int tBlockPosition = 0; 36 | private String showString = "不限"; 37 | 38 | public SearchTabMiddle(Context context) { 39 | super(context); 40 | mContext = context; 41 | init(context); 42 | } 43 | 44 | public SearchTabMiddle(Context context, AttributeSet attrs) { 45 | super(context, attrs); 46 | mContext = context; 47 | init(context); 48 | } 49 | 50 | public void updateShowText(String showArea, String showBlock) { 51 | if (showArea == null || showBlock == null) { 52 | return; 53 | } 54 | for (int i = 0; i < groups.size(); i++) { 55 | if (groups.get(i).getParName().equals(showArea)) { 56 | earaListViewAdapter.setSelectedPosition(i); 57 | childrenItem.clear(); 58 | if (i < children.size()) { 59 | childrenItem.addAll(children.get(i)); 60 | } 61 | tEaraPosition = i; 62 | break; 63 | } 64 | } 65 | for (int j = 0; j < childrenItem.size(); j++) { 66 | if (childrenItem.get(j).getParName().replace("不限", "").equals(showBlock.trim())) { 67 | plateListViewAdapter.setSelectedPosition(j); 68 | tBlockPosition = j; 69 | break; 70 | } 71 | } 72 | setDefaultSelect(); 73 | } 74 | 75 | /** 76 | * @Description: 模拟数据 77 | * @Author:胡帅 78 | * @Since: 2016年4月13日下午4:29:01 79 | */ 80 | private void testData(Context context) { 81 | 82 | SysParamsBean bean; 83 | 84 | for (int i = 0; i < 10; i++) { 85 | bean = new SysParamsBean(); 86 | bean.setParCode("" + i); 87 | if (i == 0) { 88 | bean.setParName("全部星级"); 89 | groups.add(bean); 90 | } else { 91 | bean.setParName(i + "行"); 92 | groups.add(bean); 93 | } 94 | 95 | LinkedList tItem = new LinkedList(); 96 | for (int j = 0; j < 15; j++) { 97 | SysParamsBean mBean = new SysParamsBean(); 98 | if (i != 0) { 99 | mBean.setParCode("" + j); 100 | mBean.setParName(i + "行" + j + "列"); 101 | tItem.add(mBean); 102 | } 103 | 104 | } 105 | children.put(i, tItem); 106 | } 107 | } 108 | 109 | 110 | 111 | /** 112 | * @param context 113 | * @Description:初始化视图 114 | * @Author:胡帅 115 | * @Since: 2016年4月13日下午4:29:16 116 | */ 117 | private void init(Context context) { 118 | LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 119 | inflater.inflate(R.layout.search_double_item, this, true); 120 | regionListView = (ListView) findViewById(R.id.listViewLvOne); 121 | plateListView = (ListView) findViewById(R.id.listViewLvTwo); 122 | // setBackgroundDrawable(getResources().getDrawable( 123 | // R.drawable.choosearea_bg_left)); 124 | 125 | // 测试数据 126 | testData(context); 127 | 128 | earaListViewAdapter = new SearchSysParamAdapter(context, groups, 0, 0, 0); 129 | earaListViewAdapter.setTextSize(17); 130 | earaListViewAdapter.setSelectedPositionNoNotify(tEaraPosition); 131 | regionListView.setAdapter(earaListViewAdapter); 132 | earaListViewAdapter.setOnItemClickListener(new SearchSysParamAdapter.OnItemClickListener() { 133 | 134 | @Override 135 | public void onItemClick(View view, int position) { 136 | if (position < children.size()) { 137 | if (position == 0) { 138 | if (mOnSelectListener != null) { 139 | showString = "全部星级"; 140 | mOnSelectListener.getValue(groups.get(position).getParCode(), showString); 141 | } 142 | } 143 | childrenItem.clear(); 144 | //重新获取 145 | //getSysParamList(mContext, childrenItem, groups.get(position).getParCode()); 146 | childrenItem.addAll(children.get(position)); 147 | plateListViewAdapter.notifyDataSetChanged(); 148 | } 149 | } 150 | }); 151 | if (tEaraPosition < children.size()) childrenItem.addAll(children.get(tEaraPosition)); 152 | plateListViewAdapter = new SearchSysParamAdapter(context, childrenItem, 0, 0, 1); 153 | plateListViewAdapter.setTextSize(15); 154 | // plateListViewAdapter.setSelectedPositionNoNotify(tBlockPosition); 155 | plateListView.setAdapter(plateListViewAdapter); 156 | plateListViewAdapter.setOnItemClickListener(new SearchSysParamAdapter.OnItemClickListener() { 157 | 158 | @Override 159 | public void onItemClick(View view, final int position) { 160 | 161 | showString = childrenItem.get(position).getParName(); 162 | if (mOnSelectListener != null) { 163 | 164 | mOnSelectListener.getValue(childrenItem.get(position).getParCode(), showString); 165 | } 166 | 167 | } 168 | }); 169 | if (tBlockPosition < childrenItem.size()) 170 | showString = childrenItem.get(tBlockPosition).getParName(); 171 | if (showString.contains("不限")) { 172 | showString = showString.replace("不限", ""); 173 | } 174 | setDefaultSelect(); 175 | 176 | } 177 | 178 | /** 179 | * @Description: 设置默认选中项 180 | * @Author:胡帅 181 | * @Since: 2016年4月13日下午4:27:29 182 | */ 183 | public void setDefaultSelect() { 184 | regionListView.setSelection(tEaraPosition); 185 | plateListView.setSelection(tBlockPosition); 186 | } 187 | 188 | public String getShowText() { 189 | return showString; 190 | } 191 | 192 | public void setOnSelectListener(OnSelectListener onSelectListener) { 193 | mOnSelectListener = onSelectListener; 194 | } 195 | 196 | public interface OnSelectListener { 197 | 198 | public void getValue(String itemLvTwocode, String showText); 199 | } 200 | 201 | @Override 202 | public void hide() { 203 | 204 | } 205 | 206 | @Override 207 | public void show() { 208 | 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /app/src/main/java/com/voids/ben/searchexpandtabview/expandtabview/SearchTabRight.java: -------------------------------------------------------------------------------- 1 | package com.voids.ben.searchexpandtabview.expandtabview; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.widget.ListView; 8 | import android.widget.RelativeLayout; 9 | 10 | import com.voids.ben.searchexpandtabview.R; 11 | import com.voids.ben.searchexpandtabview.adapter.SearchSysParamAdapter; 12 | import com.voids.ben.searchexpandtabview.bean.SysParamsBean; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | 18 | /** 19 | *@Description:expandTab 右 专业特长item 20 | *@Author:ben 21 | *@Since:2016年4月13日下午2:33:17 22 | */ 23 | public class SearchTabRight extends RelativeLayout implements ViewBaseAction { 24 | 25 | private ListView mListView; 26 | private List specialtyList; 27 | private final String[] items = new String[] {"全部特长", "item1", "item2", "item3", "item4", "item5", "item6","item7","item8" };//显示字段 28 | private final String[] itemsVaule = new String[] { "1", "2", "3", "4", "5", "6","7","8","9" };//隐藏id 29 | private OnSelectListener mOnSelectListener; 30 | private SearchSysParamAdapter adapter; 31 | private String mDistance; 32 | private long selectId; 33 | private String showText = "地区"; 34 | private Context mContext; 35 | 36 | public String getShowText() { 37 | return showText; 38 | } 39 | 40 | public SearchTabRight(Context context) { 41 | super(context); 42 | init(context); 43 | } 44 | 45 | public SearchTabRight(Context context, AttributeSet attrs, int defStyle) { 46 | super(context, attrs, defStyle); 47 | init(context); 48 | } 49 | 50 | public SearchTabRight(Context context, AttributeSet attrs) { 51 | super(context, attrs); 52 | init(context); 53 | } 54 | 55 | //test数据 56 | private void testData(){ 57 | specialtyList = new ArrayList (); 58 | SysParamsBean bean; 59 | for ( int i = 0 ; i < items.length ; i++ ) { 60 | bean = new SysParamsBean(); 61 | bean.setParName (items[i]); 62 | bean.setParCode (""+i); 63 | specialtyList.add (bean); 64 | } 65 | } 66 | 67 | 68 | /** 69 | *@Description: 初始化视图 70 | *@Author:胡帅 71 | *@Since: 2016年4月13日下午4:30:26 72 | *@param context 73 | */ 74 | private void init(Context context) { 75 | mContext = context; 76 | LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 77 | inflater.inflate(R.layout.search_single_item, this, true); 78 | //setBackgroundDrawable(getResources().getDrawable(R.drawable.choosearea_bg_mid)); 79 | mListView = (ListView) findViewById(R.id.listViewSingle); 80 | 81 | testData(); 82 | adapter = new SearchSysParamAdapter(context, specialtyList, 0, 0,0); 83 | 84 | adapter.setSelectedPosition (0); 85 | adapter.setTextSize(17); 86 | if (mDistance != null) { 87 | for (int i = 0; i < specialtyList.size (); i++) { 88 | if (specialtyList.get (i).getId ()==selectId) { 89 | adapter.setSelectedPositionNoNotify(i); 90 | showText = specialtyList.get (i).getParName (); 91 | break; 92 | } 93 | } 94 | } 95 | mListView.setAdapter(adapter); 96 | adapter.setOnItemClickListener(new SearchSysParamAdapter.OnItemClickListener() { 97 | 98 | @Override 99 | public void onItemClick(View view, int position) { 100 | 101 | if (mOnSelectListener != null) { 102 | showText = specialtyList.get (position).getParName (); 103 | mOnSelectListener.getValue(specialtyList.get (position).getParCode (), specialtyList.get (position).getParName ()); 104 | } 105 | } 106 | }); 107 | } 108 | 109 | public void setOnSelectListener(OnSelectListener onSelectListener) { 110 | mOnSelectListener = onSelectListener; 111 | } 112 | 113 | public interface OnSelectListener { 114 | public void getValue(String itemCode, String showText); 115 | } 116 | 117 | @Override 118 | public void hide() { 119 | 120 | } 121 | 122 | @Override 123 | public void show() { 124 | 125 | } 126 | 127 | } 128 | 129 | -------------------------------------------------------------------------------- /app/src/main/java/com/voids/ben/searchexpandtabview/expandtabview/SearchTabView.java: -------------------------------------------------------------------------------- 1 | package com.voids.ben.searchexpandtabview.expandtabview; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.util.AttributeSet; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.widget.LinearLayout; 9 | import android.widget.PopupWindow; 10 | import android.widget.RelativeLayout; 11 | import android.widget.ToggleButton; 12 | import android.widget.PopupWindow.OnDismissListener; 13 | 14 | import com.voids.ben.searchexpandtabview.R; 15 | 16 | import java.util.ArrayList; 17 | 18 | /** 19 | *@Description:菜单控件头部 封装了下拉动画 动态生成头部按钮个数 20 | *@Author:ben 21 | *@Since:2016年4月13日下午12:54:01 22 | */ 23 | public class SearchTabView extends LinearLayout implements OnDismissListener { 24 | 25 | private ToggleButton selectedButton; 26 | private ArrayList mTextArray = new ArrayList (); 27 | private ArrayList mViewArray = new ArrayList (); 28 | private ArrayList mToggleButton = new ArrayList (); 29 | private Context mContext; 30 | private final int SMALL = 0; 31 | private int displayWidth; 32 | private int displayHeight; 33 | private PopupWindow popupWindow; 34 | private int selectPosition; 35 | 36 | public SearchTabView(Context context) { 37 | super (context); 38 | init (context); 39 | } 40 | 41 | public SearchTabView(Context context, AttributeSet attrs) { 42 | super (context, attrs); 43 | init (context); 44 | } 45 | 46 | /** 47 | * 根据选择的位置设置tabitem显示的值 48 | */ 49 | public void setTitle(String valueText,int position){ 50 | if (position < mToggleButton.size ()) { 51 | mToggleButton.get (position).setText (valueText); 52 | } 53 | } 54 | 55 | /** 56 | * 根据选择的位置获取tabitem显示的值 57 | */ 58 | public String getTitle(int position){ 59 | if (position < mToggleButton.size () && mToggleButton.get (position).getText () != null) { return mToggleButton.get (position).getText ().toString (); } 60 | return ""; 61 | } 62 | 63 | /** 64 | * 设置tabitem的个数和初始值 65 | */ 66 | public void setValue(ArrayList textArray,ArrayList viewArray){ 67 | if (mContext == null) { return; } 68 | LayoutInflater inflater = (LayoutInflater) mContext.getSystemService (Context.LAYOUT_INFLATER_SERVICE); 69 | 70 | mTextArray = textArray; 71 | for ( int i = 0 ; i < viewArray.size () ; i++ ) { 72 | final RelativeLayout r = new RelativeLayout (mContext); 73 | int maxHeight = (int) (displayHeight * 0.7); 74 | RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams (RelativeLayout.LayoutParams.MATCH_PARENT,maxHeight); 75 | rl.leftMargin = 0; 76 | rl.rightMargin = 0; 77 | r.addView (viewArray.get (i), rl); 78 | mViewArray.add (r); 79 | r.setTag (SMALL); 80 | ToggleButton tButton = (ToggleButton) inflater.inflate (R.layout.btn_taggle_search, this, false); 81 | addView (tButton); 82 | 83 | // 分割线设置 84 | View line = new View (mContext); 85 | line.setBackgroundColor (mContext.getResources ().getColor (R.color.text_hint)); 86 | // line.setTop (10); 87 | // line.setBottom (10); 88 | LinearLayout.LayoutParams lp; 89 | if (i < viewArray.size () - 1) { 90 | lp = new LinearLayout.LayoutParams (1,LinearLayout.LayoutParams.MATCH_PARENT); 91 | lp.setMargins (0, 10, 0, 10); 92 | addView (line, lp); 93 | 94 | } 95 | mToggleButton.add (tButton); 96 | tButton.setTag (i); 97 | tButton.setText (mTextArray.get (i)); 98 | 99 | r.setOnClickListener (new OnClickListener () { 100 | 101 | @Override 102 | public void onClick(View v){ 103 | onPressBack (); 104 | } 105 | }); 106 | 107 | r.setBackgroundColor (mContext.getResources ().getColor (R.color.popup_main_background)); 108 | tButton.setOnClickListener (new OnClickListener () { 109 | 110 | @Override 111 | public void onClick(View view){ 112 | // initPopupWindow(); 113 | ToggleButton tButton = (ToggleButton) view; 114 | 115 | if (selectedButton != null && selectedButton != tButton) { 116 | selectedButton.setChecked (false); 117 | } 118 | selectedButton = tButton; 119 | selectPosition = (Integer) selectedButton.getTag (); 120 | startAnimation (); 121 | if (mOnButtonClickListener != null && tButton.isChecked ()) { 122 | mOnButtonClickListener.onClick (selectPosition); 123 | } 124 | } 125 | }); 126 | } 127 | } 128 | 129 | /** 130 | *@Description: 设置动画 131 | *@Author:胡帅 132 | *@Since: 2016年4月13日下午2:53:53 133 | */ 134 | private void startAnimation(){ 135 | 136 | if (popupWindow == null) { 137 | popupWindow = new PopupWindow (mViewArray.get (selectPosition),displayWidth,displayHeight); 138 | popupWindow.setAnimationStyle (R.style.PopupWindowAnimation); 139 | popupWindow.setFocusable (false); 140 | popupWindow.setOutsideTouchable (true); 141 | } 142 | 143 | if (selectedButton.isChecked ()) { 144 | if (!popupWindow.isShowing ()) { 145 | showPopup (selectPosition); 146 | } else { 147 | popupWindow.setOnDismissListener (this); 148 | popupWindow.dismiss (); 149 | hideView (); 150 | } 151 | } else { 152 | if (popupWindow.isShowing ()) { 153 | popupWindow.dismiss (); 154 | hideView (); 155 | } 156 | } 157 | } 158 | 159 | private void showPopup(int position){ 160 | View tView = mViewArray.get (selectPosition).getChildAt (0); 161 | if (tView instanceof ViewBaseAction) { 162 | ViewBaseAction f = (ViewBaseAction) tView; 163 | f.show (); 164 | } 165 | if (popupWindow.getContentView () != mViewArray.get (position)) { 166 | popupWindow.setContentView (mViewArray.get (position)); 167 | } 168 | popupWindow.showAsDropDown (this, 0, 0); 169 | } 170 | 171 | /** 172 | * 如果菜单成展开状态,则让菜单收回去 173 | */ 174 | public boolean onPressBack(){ 175 | if (popupWindow != null && popupWindow.isShowing ()) { 176 | popupWindow.dismiss (); 177 | hideView (); 178 | if (selectedButton != null) { 179 | selectedButton.setChecked (false); 180 | } 181 | return true; 182 | } else { 183 | return false; 184 | } 185 | 186 | } 187 | 188 | private void hideView(){ 189 | View tView = mViewArray.get (selectPosition).getChildAt (0); 190 | if (tView instanceof ViewBaseAction) { 191 | ViewBaseAction f = (ViewBaseAction) tView; 192 | f.hide (); 193 | } 194 | } 195 | 196 | private void init(Context context){ 197 | mContext = context; 198 | displayWidth = ((Activity) mContext).getWindowManager ().getDefaultDisplay ().getWidth (); 199 | displayHeight = ((Activity) mContext).getWindowManager ().getDefaultDisplay ().getHeight (); 200 | setOrientation (LinearLayout.HORIZONTAL); 201 | } 202 | 203 | @Override 204 | public void onDismiss(){ 205 | showPopup (selectPosition); 206 | popupWindow.setOnDismissListener (null); 207 | } 208 | 209 | private OnButtonClickListener mOnButtonClickListener; 210 | 211 | /** 212 | * 设置tabitem的点击监听事件 213 | */ 214 | public void setOnButtonClickListener(OnButtonClickListener l){ 215 | mOnButtonClickListener = l; 216 | } 217 | 218 | /** 219 | * 自定义tabitem点击回调接口 220 | */ 221 | public interface OnButtonClickListener { 222 | 223 | public void onClick(int selectPosition); 224 | } 225 | 226 | } -------------------------------------------------------------------------------- /app/src/main/java/com/voids/ben/searchexpandtabview/expandtabview/ViewBaseAction.java: -------------------------------------------------------------------------------- 1 | package com.voids.ben.searchexpandtabview.expandtabview; 2 | 3 | /** 4 | * Created by ben 5 | */ 6 | public interface ViewBaseAction { 7 | 8 | /** 9 | * 菜单隐藏操作 10 | */ 11 | public void hide(); 12 | 13 | /** 14 | * 菜单显示操作 15 | */ 16 | public void show(); 17 | } -------------------------------------------------------------------------------- /app/src/main/java/com/voids/ben/searchexpandtabview/mApplication.java: -------------------------------------------------------------------------------- 1 | package com.voids.ben.searchexpandtabview; 2 | 3 | import android.app.Application; 4 | import android.graphics.Bitmap; 5 | 6 | import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache; 7 | import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache; 8 | import com.nostra13.universalimageloader.core.DisplayImageOptions; 9 | import com.nostra13.universalimageloader.core.ImageLoader; 10 | import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; 11 | import com.nostra13.universalimageloader.core.assist.ImageScaleType; 12 | import com.nostra13.universalimageloader.core.assist.QueueProcessingType; 13 | 14 | import java.io.File; 15 | 16 | /** 17 | * Created by ben on 16/5/1. 18 | */ 19 | public class mApplication extends Application { 20 | private static String IMAGE_CACHE_PATH = "imageloader/Cache"; // 图片缓存路径 21 | 22 | @Override 23 | public void onCreate() { 24 | super.onCreate(); 25 | 26 | initImageLoader(); 27 | } 28 | private void initImageLoader() { 29 | File cacheDir = com.nostra13.universalimageloader.utils.StorageUtils 30 | .getOwnCacheDirectory(getApplicationContext(), IMAGE_CACHE_PATH); 31 | 32 | DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() 33 | .showImageOnLoading(R.mipmap.pic1) 34 | .showImageForEmptyUri(R.mipmap.pic2) 35 | .showImageOnFail(R.mipmap.pic4) 36 | .cacheInMemory(true).cacheOnDisk(true) 37 | .bitmapConfig(Bitmap.Config.RGB_565) 38 | .imageScaleType(ImageScaleType.EXACTLY).build(); 39 | 40 | ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder( 41 | this).defaultDisplayImageOptions(defaultOptions) 42 | .memoryCache(new LruMemoryCache(12 * 1024 * 1024)) 43 | .memoryCacheSize(12 * 1024 * 1024) 44 | .diskCacheSize(32 * 1024 * 1024).diskCacheFileCount(100) 45 | .diskCache(new UnlimitedDiscCache(cacheDir)) 46 | .threadPriority(Thread.NORM_PRIORITY - 2) 47 | .tasksProcessingOrder(QueueProcessingType.LIFO).build(); 48 | 49 | ImageLoader.getInstance().init(config); 50 | } 51 | 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/res/anim/pophidden_anim.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/anim/popshow_anim.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_edit.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/search_choose_item_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/selector_expand_tab.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/selector_searchtab_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 16 | 17 | 25 | 26 |