├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable
│ │ │ │ └── item_bg.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── item_child.xml
│ │ │ │ ├── item_normal.xml
│ │ │ │ ├── item_group.xml
│ │ │ │ ├── sub_edit.xml
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── zyw
│ │ │ │ └── horrarndoo
│ │ │ │ └── nestingrecyclerviewdemo
│ │ │ │ ├── bean
│ │ │ │ ├── NormalItemBean.java
│ │ │ │ ├── ChildItemBean.java
│ │ │ │ ├── GroupItemBean.java
│ │ │ │ └── DemoItemBean.java
│ │ │ │ ├── adapter
│ │ │ │ ├── OnCheckChangeListener.java
│ │ │ │ ├── ViewHolder
│ │ │ │ │ ├── NormalViewHolder.java
│ │ │ │ │ ├── ChildViewHolder.java
│ │ │ │ │ └── GroupViewHolder.java
│ │ │ │ └── DemoAdapter.java
│ │ │ │ ├── MyApplication.java
│ │ │ │ ├── utils
│ │ │ │ ├── ToastUtils.java
│ │ │ │ └── AppUtils.java
│ │ │ │ ├── helper
│ │ │ │ └── ParseHelper.java
│ │ │ │ └── ui
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── zyw
│ │ │ └── horrarndoo
│ │ │ └── nestingrecyclerviewdemo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── zyw
│ │ └── horrarndoo
│ │ └── nestingrecyclerviewdemo
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── assets
└── GIF.gif
├── .idea
├── copyright
│ └── profiles_settings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/assets/GIF.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/NestingRecyclerViewDemo/HEAD/assets/GIF.gif
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | NestingRecyclerViewDemo
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/NestingRecyclerViewDemo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/NestingRecyclerViewDemo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/NestingRecyclerViewDemo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/NestingRecyclerViewDemo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/NestingRecyclerViewDemo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/NestingRecyclerViewDemo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/item_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/nestingrecyclerviewdemo/bean/NormalItemBean.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.nestingrecyclerviewdemo.bean;
2 |
3 | /**
4 | * Created by Horrarndoo on 2017/11/22.
5 | *
6 | */
7 |
8 | public class NormalItemBean extends DemoItemBean {
9 | }
10 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #FFFAFA
8 |
9 | #ffe599
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # NestingRecyclerViewDemo
2 | 使用单RecyclerView实现RecyclerView嵌套RecyclerView(购物车)效果demo,包括增删选中等演示功能
3 |
4 | 
5 |
6 | 详细介绍:
7 |
8 | [CSDN-换种思路实现RecyclerView嵌套RecyclerView(购物车)复杂效果](http://blog.csdn.net/oQinYou/article/details/78630655)
9 |
10 | [简书-换种思路实现RecyclerView嵌套RecyclerView(购物车)复杂效果](http://www.jianshu.com/p/92bcf382d24d)
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/nestingrecyclerviewdemo/bean/ChildItemBean.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.nestingrecyclerviewdemo.bean;
2 |
3 | /**
4 | * Created by Horrarndoo on 2017/11/22.
5 | *
6 | */
7 |
8 | public class ChildItemBean extends DemoItemBean{
9 | private int groupId;
10 |
11 | public int getGroupId() {
12 | return groupId;
13 | }
14 |
15 | public void setGroupId(int groupId) {
16 | this.groupId = groupId;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/nestingrecyclerviewdemo/adapter/OnCheckChangeListener.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.nestingrecyclerviewdemo.adapter;
2 |
3 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.bean.DemoItemBean;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by Horrarndoo on 2017/11/24.
9 | *
10 | */
11 |
12 | public interface OnCheckChangeListener {
13 | void onCheckedChanged(Listbeans, int position, boolean isChecked, int itemType);
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/nestingrecyclerviewdemo/bean/GroupItemBean.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.nestingrecyclerviewdemo.bean;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by Horrarndoo on 2017/11/22.
7 | *
8 | */
9 |
10 | public class GroupItemBean extends DemoItemBean{
11 | private List childs;
12 |
13 | public List getChilds() {
14 | return childs;
15 | }
16 |
17 | public void setChilds(List childs) {
18 | this.childs = childs;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/test/java/com/zyw/horrarndoo/nestingrecyclerviewdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.nestingrecyclerviewdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/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 C:\Users\Administrator\AppData\Local\Android\Sdk/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 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/zyw/horrarndoo/nestingrecyclerviewdemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.nestingrecyclerviewdemo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.zyw.horrarndoo.nestingrecyclerviewdemo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "26.0.2"
6 | defaultConfig {
7 | applicationId "com.zyw.horrarndoo.nestingrecyclerviewdemo"
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
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 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.3.1'
28 | compile "com.android.support:recyclerview-v7:25.3.1"
29 | testCompile 'junit:junit:4.12'
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/nestingrecyclerviewdemo/bean/DemoItemBean.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.nestingrecyclerviewdemo.bean;
2 |
3 | /**
4 | * Created by Horrarndoo on 2017/11/22.
5 | *
6 | */
7 |
8 | public class DemoItemBean {
9 | public static final int TYPE_NORMAL = 0;
10 | public static final int TYPE_GROUP = 1;
11 | public static final int TYPE_CHILD = 2;
12 |
13 | private String title;
14 | private boolean isChecked;
15 | private int itemType;
16 | private int itemId;
17 |
18 | public boolean isChecked() {
19 | return isChecked;
20 | }
21 |
22 | public void setChecked(boolean checked) {
23 | isChecked = checked;
24 | }
25 |
26 | public int getItemId() {
27 | return itemId;
28 | }
29 |
30 | public void setItemId(int itemId) {
31 | this.itemId = itemId;
32 | }
33 |
34 | public String getTitle() {
35 | return title;
36 | }
37 |
38 | public void setTitle(String title) {
39 | this.title = title;
40 | }
41 |
42 | public int getItemType() {
43 | return itemType;
44 | }
45 |
46 | public void setItemType(int itemType) {
47 | this.itemType = itemType;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/nestingrecyclerviewdemo/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.nestingrecyclerviewdemo;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 | import android.os.Handler;
6 |
7 | /**
8 | * Created by Horrarndoo on 2017/11/24.
9 | *
10 | */
11 |
12 | public class MyApplication extends Application{
13 | protected static Context context;
14 | protected static Handler handler;
15 | protected static int mainThreadId;
16 |
17 | @Override
18 | public void onCreate() {
19 | super.onCreate();
20 | context = getApplicationContext();
21 | handler = new Handler();
22 | mainThreadId = android.os.Process.myTid();
23 | }
24 |
25 | /**
26 | * 获取上下文对象
27 | *
28 | * @return context
29 | */
30 | public static Context getContext() {
31 | return context;
32 | }
33 |
34 | /**
35 | * 获取全局handler
36 | *
37 | * @return 全局handler
38 | */
39 | public static Handler getHandler() {
40 | return handler;
41 | }
42 |
43 | /**
44 | * 获取主线程id
45 | *
46 | * @return 主线程id
47 | */
48 | public static int getMainThreadId() {
49 | return mainThreadId;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_child.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
14 |
15 |
20 |
21 |
29 |
30 |
31 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_normal.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
23 |
24 |
30 |
31 |
32 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_group.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
19 |
20 |
28 |
29 |
30 |
34 |
35 |
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/nestingrecyclerviewdemo/adapter/ViewHolder/NormalViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.nestingrecyclerviewdemo.adapter.ViewHolder;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.View;
5 | import android.widget.CheckBox;
6 | import android.widget.LinearLayout;
7 | import android.widget.TextView;
8 |
9 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.R;
10 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.bean.NormalItemBean;
11 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.utils.ToastUtils;
12 |
13 | /**
14 | * Created by Horrarndoo on 2017/11/24.
15 | *
16 | */
17 |
18 | public class NormalViewHolder extends RecyclerView.ViewHolder {
19 | private NormalItemBean bean;
20 | public TextView tvNormal;
21 | public LinearLayout llNormal;
22 | public CheckBox cbNormal;
23 |
24 | public NormalViewHolder(View itemView) {
25 | super(itemView);
26 | tvNormal = (TextView) itemView.findViewById(R.id.tv_normal);
27 | llNormal = (LinearLayout) itemView.findViewById(R.id.ll_normal);
28 | cbNormal = (CheckBox) itemView.findViewById(R.id.cb_normal);
29 | llNormal.setOnClickListener(new OnClickListener());
30 | }
31 |
32 | /**
33 | * 绑定item数据
34 | * @param bean item数据
35 | */
36 | public void bindData(NormalItemBean bean){
37 | this.bean = bean;
38 | }
39 |
40 | private class OnClickListener implements View.OnClickListener {
41 | @Override
42 | public void onClick(View v) {
43 | switch (v.getId()) {
44 | case R.id.ll_normal:
45 | ToastUtils.showToast(bean.getTitle() + " is clicked.");
46 | break;
47 | }
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/nestingrecyclerviewdemo/adapter/ViewHolder/ChildViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.nestingrecyclerviewdemo.adapter.ViewHolder;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.View;
5 | import android.widget.CheckBox;
6 | import android.widget.LinearLayout;
7 | import android.widget.TextView;
8 |
9 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.R;
10 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.bean.ChildItemBean;
11 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.utils.ToastUtils;
12 |
13 | /**
14 | * Created by Horrarndoo on 2017/11/24.
15 | *
16 | */
17 |
18 | public class ChildViewHolder extends RecyclerView.ViewHolder {
19 | private ChildItemBean bean;
20 | public TextView tvChild;
21 | public CheckBox cbChild;
22 | public LinearLayout llChild;
23 |
24 | public ChildViewHolder(View itemView) {
25 | super(itemView);
26 |
27 | tvChild = (TextView) itemView.findViewById(R.id.tv_child);
28 | cbChild = (CheckBox) itemView.findViewById(R.id.cb_child);
29 | llChild = (LinearLayout) itemView.findViewById(R.id.ll_child);
30 |
31 | llChild.setOnClickListener(new OnClickListener());
32 | }
33 |
34 | /**
35 | * 绑定item数据
36 | *
37 | * @param bean item数据
38 | */
39 | public void bindData(ChildItemBean bean) {
40 | this.bean = bean;
41 | }
42 |
43 | private class OnClickListener implements View.OnClickListener {
44 | @Override
45 | public void onClick(View v) {
46 | switch (v.getId()) {
47 | case R.id.ll_child:
48 | ToastUtils.showToast(bean.getTitle() + " is clicked.");
49 | break;
50 | }
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/nestingrecyclerviewdemo/utils/ToastUtils.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.nestingrecyclerviewdemo.utils;
2 |
3 | import android.content.Context;
4 | import android.widget.Toast;
5 |
6 | /**
7 | * Created by Horrarndoo on 2017/4/5.
8 | *
9 | * toast工具类封装
10 | */
11 | public class ToastUtils {
12 | private static Toast mToast = null;
13 |
14 | /**
15 | * 显示一个toast提示
16 | *
17 | * @param resouceId toast字符串资源id
18 | */
19 | public static void showToast(int resouceId) {
20 | showToast(AppUtils.getString(resouceId));
21 | }
22 |
23 | /**
24 | * 显示一个toast提示
25 | *
26 | * @param text toast字符串
27 | */
28 | public static void showToast(String text) {
29 | showToast(text, Toast.LENGTH_SHORT);
30 | }
31 |
32 | /**
33 | * 显示一个toast提示
34 | *
35 | * @param text toast字符串
36 | * @param duration toast显示时间
37 | */
38 | public static void showToast(String text, int duration) {
39 | showToast(AppUtils.getContext(), text, duration);
40 | }
41 |
42 | /**
43 | * 显示一个toast提示
44 | *
45 | * @param context context 上下文对象
46 | * @param text toast字符串
47 | * @param duration toast显示时间
48 | */
49 | public static void showToast(final Context context, final String text, final int duration) {
50 | /**
51 | * 保证运行在主线程
52 | */
53 | AppUtils.runOnUIThread(new Runnable() {
54 | @Override
55 | public void run() {
56 | if (mToast == null) {
57 | mToast = Toast.makeText(context, text, duration);
58 | } else {
59 | mToast.setText(text);
60 | mToast.setDuration(duration);
61 | }
62 | mToast.show();
63 | }
64 | });
65 | }
66 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/sub_edit.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
22 |
23 |
32 |
33 |
37 |
38 |
47 |
48 |
52 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
18 |
24 |
25 |
33 |
34 |
42 |
43 |
44 |
52 |
53 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | C:\Users\Administrator\AppData\Roaming\Subversion
48 |
49 |
50 |
51 |
52 |
53 | 1.8
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/nestingrecyclerviewdemo/adapter/ViewHolder/GroupViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.nestingrecyclerviewdemo.adapter.ViewHolder;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.View;
5 | import android.widget.CheckBox;
6 | import android.widget.LinearLayout;
7 | import android.widget.TextView;
8 |
9 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.R;
10 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.bean.GroupItemBean;
11 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.utils.ToastUtils;
12 |
13 | /**
14 | * Created by Horrarndoo on 2017/11/24.
15 | *
16 | */
17 |
18 | public class GroupViewHolder extends RecyclerView.ViewHolder {
19 | private GroupItemBean bean;
20 | public TextView tvGroup, tvSub1, tvSub2, tvSub3;
21 | public CheckBox cbGroup;
22 | public LinearLayout llGroup, subEdit;
23 |
24 | public GroupViewHolder(View itemView) {
25 | super(itemView);
26 | tvGroup = (TextView) itemView.findViewById(R.id.tv_group);
27 | cbGroup = (CheckBox) itemView.findViewById(R.id.cb_group);
28 | llGroup = (LinearLayout) itemView.findViewById(R.id.ll_group);
29 | subEdit = (LinearLayout) itemView.findViewById(R.id.sub_edit);
30 | tvSub1 = (TextView) itemView.findViewById(R.id.tv_sub_1);
31 | tvSub2 = (TextView) itemView.findViewById(R.id.tv_sub_2);
32 | tvSub3 = (TextView) itemView.findViewById(R.id.tv_sub_3);
33 |
34 | llGroup.setOnLongClickListener(new View.OnLongClickListener() {
35 | @Override
36 | public boolean onLongClick(View v) {
37 | subEdit.setVisibility(View.VISIBLE);
38 | return true;
39 | }
40 | });
41 |
42 | llGroup.setOnClickListener(new OnClickListener());
43 | tvSub1.setOnClickListener(new OnClickListener());
44 | tvSub2.setOnClickListener(new OnClickListener());
45 | tvSub3.setOnClickListener(new OnClickListener());
46 | }
47 |
48 | /**
49 | * 绑定item数据
50 | * @param bean item数据
51 | */
52 | public void bindData(GroupItemBean bean){
53 | this.bean = bean;
54 | }
55 |
56 | private class OnClickListener implements View.OnClickListener {
57 | @Override
58 | public void onClick(View v) {
59 | subEdit.setVisibility(View.GONE);
60 | switch (v.getId()) {
61 | case R.id.ll_group:
62 | ToastUtils.showToast(bean.getTitle() + " is clicked.");
63 | break;
64 | case R.id.tv_sub_1:
65 | ToastUtils.showToast(bean.getTitle() + " subItem 1 is clicked.");
66 | break;
67 | case R.id.tv_sub_2:
68 | ToastUtils.showToast(bean.getTitle() + " subItem 2 is clicked.");
69 | break;
70 | case R.id.tv_sub_3:
71 | ToastUtils.showToast(bean.getTitle() + " subItem 3 is clicked.");
72 | break;
73 | }
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/nestingrecyclerviewdemo/helper/ParseHelper.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.nestingrecyclerviewdemo.helper;
2 |
3 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.bean.ChildItemBean;
4 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.bean.DemoItemBean;
5 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.bean.GroupItemBean;
6 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.bean.NormalItemBean;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | * Created by Horrarndoo on 2017/11/23.
13 | *
14 | */
15 |
16 | public class ParseHelper {
17 | //=========== 这里模拟服务器返回的数据 ==========
18 | private static List getNormalDatas() {
19 | List list = new ArrayList<>();
20 | for (int i = 0; i < 5; i++) {
21 | NormalItemBean bean = new NormalItemBean();
22 | bean.setItemId(i);
23 | bean.setChecked(false);
24 | bean.setItemType(DemoItemBean.TYPE_NORMAL);
25 | bean.setTitle("Normal: " + i);
26 | list.add(bean);
27 | }
28 | return list;
29 | }
30 |
31 | private static List getGroupDatas() {
32 | List list = new ArrayList<>();
33 | for (int i = 0; i < 5; i++) {
34 | List childList = new ArrayList<>();
35 | GroupItemBean bean = new GroupItemBean();
36 | bean.setItemId(i);
37 | bean.setItemType(DemoItemBean.TYPE_GROUP);
38 | bean.setTitle("Group: " + i);
39 | bean.setChecked(false);
40 |
41 | for (int j = 0; j < 3; j++) {
42 | ChildItemBean bean1 = new ChildItemBean();
43 | bean1.setTitle("group: " + i + " child: " + j);
44 | bean1.setChecked(false);
45 | bean1.setItemType(DemoItemBean.TYPE_CHILD);
46 | bean1.setGroupId(i);//child的groupId对应当前
47 | bean1.setItemId(bean.getItemId());//child的itemId和其父group的itemId一致
48 | childList.add(bean1);
49 | }
50 | bean.setChilds(childList);
51 | list.add(bean);
52 | }
53 | return list;
54 | }
55 | //===============================================
56 |
57 | public static List getParseDatas() {
58 | List list = new ArrayList<>();
59 |
60 | for (NormalItemBean bean : getNormalDatas()) {
61 | list.add(bean);//normal
62 | }
63 |
64 | for (GroupItemBean bean : getGroupDatas()) {
65 | list.add(bean);//group
66 |
67 | for (ChildItemBean bean1 : bean.getChilds()) {
68 | list.add(bean1);//child
69 | }
70 | }
71 | return list;
72 | }
73 |
74 | /**
75 | * 获取group下的child list
76 | *
77 | * @param beans 整个数据list
78 | * @param position 当前group的position
79 | */
80 | public static List getChildList(List beans, int position) {
81 | List childList = new ArrayList<>();
82 | for (DemoItemBean bean : beans) {
83 | //item id不相同直接跳过
84 | if (bean.getItemId() != beans.get(position).getItemId())
85 | continue;
86 |
87 | if (bean.getItemType() == DemoItemBean.TYPE_CHILD) {
88 | childList.add((ChildItemBean) bean);
89 | }
90 | }
91 | return childList;
92 | }
93 |
94 | /**
95 | * 取出list中的groupBean
96 | *
97 | * @param beans
98 | * @param itemId
99 | * @return
100 | */
101 | public static GroupItemBean getGroupBean(List beans, int itemId) {
102 | for (DemoItemBean bean : beans) {
103 | if (bean.getItemType() == DemoItemBean.TYPE_GROUP && bean.getItemId() == itemId)
104 | return (GroupItemBean) bean;
105 | }
106 | return null;
107 | }
108 |
109 | /**
110 | * 根据itemId获取child所在的group的position
111 | *
112 | * @param beans 整个数据list
113 | * @param itemId child的itemId
114 | * @return group的position
115 | */
116 | public static int getGroupPosition(List beans, int itemId) {
117 | for (int i = 0; i < beans.size(); i++) {
118 | if (beans.get(i).getItemType() == DemoItemBean.TYPE_GROUP
119 | && beans.get(i).getItemId() == itemId)
120 | return i;
121 | }
122 | return 0;
123 | }
124 |
125 | /**
126 | * new一个normal item数据
127 | *
128 | * @param itemId position
129 | * @return normal item数据
130 | */
131 | public static NormalItemBean newNormalItem(int itemId) {
132 | NormalItemBean bean = new NormalItemBean();
133 | bean.setItemId(itemId);
134 | bean.setChecked(false);
135 | bean.setTitle("Normal: " + itemId);
136 | bean.setItemType(DemoItemBean.TYPE_NORMAL);
137 | return bean;
138 | }
139 |
140 | public static GroupItemBean newGroupItem(int itemId) {
141 | List childList = new ArrayList<>();
142 | GroupItemBean bean = new GroupItemBean();
143 | bean.setItemId(itemId);
144 | bean.setItemType(DemoItemBean.TYPE_GROUP);
145 | bean.setTitle("Group: " + itemId);
146 | bean.setChilds(childList);
147 | bean.setChecked(false);
148 | return bean;
149 | }
150 |
151 | public static ChildItemBean newChildItem(List beans, int itemId, int childId) {
152 | GroupItemBean groupItemBean = getGroupBean(beans, itemId);
153 | ChildItemBean bean = new ChildItemBean();
154 | bean.setGroupId(itemId);
155 | bean.setItemId(itemId);
156 | bean.setItemType(DemoItemBean.TYPE_CHILD);
157 | bean.setTitle("group: " + itemId + " child: " + childId);
158 | bean.setChecked(false);
159 | if (groupItemBean != null)
160 | groupItemBean.getChilds().add(bean);
161 | return bean;
162 | }
163 | }
164 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/nestingrecyclerviewdemo/utils/AppUtils.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.nestingrecyclerviewdemo.utils;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.pm.PackageInfo;
6 | import android.content.pm.PackageManager;
7 | import android.content.res.ColorStateList;
8 | import android.graphics.Rect;
9 | import android.graphics.drawable.Drawable;
10 | import android.os.Build;
11 | import android.os.Handler;
12 | import android.view.View;
13 | import android.view.Window;
14 | import android.view.WindowManager;
15 |
16 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.MyApplication;
17 |
18 | /**
19 | * Created by Horrarndoo on 2017/4/5.
20 | * 系统界面工具类
21 | */
22 | public class AppUtils {
23 | /**
24 | * 获取上下文对象
25 | *
26 | * @return
27 | */
28 | public static Context getContext() {
29 | return MyApplication.getContext();
30 | }
31 |
32 | /**
33 | * 获取全局handler
34 | *
35 | * @return
36 | */
37 | public static Handler getHandler() {
38 | return MyApplication.getHandler();
39 | }
40 |
41 | /**
42 | * 获取主线程id
43 | *
44 | * @return
45 | */
46 | public static int getMainThreadId() {
47 | return MyApplication.getMainThreadId();
48 | }
49 |
50 | ///////////////////加载资源文件 /////////////////////
51 |
52 | /**
53 | * 获取strings.xml资源文件字符串
54 | *
55 | * @param id 资源文件id
56 | * @return 资源文件对应字符串
57 | */
58 | public static String getString(int id) {
59 | return getContext().getResources().getString(id);
60 | }
61 |
62 | /**
63 | * 获取strings.xml资源文件字符串数组
64 | *
65 | * @param id 资源文件id
66 | * @return 资源文件对应字符串数组
67 | */
68 | public static String[] getStringArray(int id) {
69 | return getContext().getResources().getStringArray(id);
70 | }
71 |
72 | /**
73 | * 获取drawable资源文件图片
74 | *
75 | * @param id 资源文件id
76 | * @return 资源文件对应图片
77 | */
78 | public static Drawable getDrawable(int id) {
79 | return getContext().getResources().getDrawable(id);
80 | }
81 |
82 | /**
83 | * 获取colors.xml资源文件颜色
84 | *
85 | * @param id 资源文件id
86 | * @return 资源文件对应颜色值
87 | */
88 | public static int getColor(int id) {
89 | return getContext().getResources().getColor(id);
90 | }
91 |
92 | /**
93 | * 获取颜色的状态选择器
94 | *
95 | * @param id 资源文件id
96 | * @return 资源文件对应颜色状态
97 | */
98 | public static ColorStateList getColorStateList(int id) {
99 | return getContext().getResources().getColorStateList(id);
100 | }
101 |
102 | /**
103 | * 获取dimens资源文件中具体像素值
104 | *
105 | * @param id 资源文件id
106 | * @return 资源文件对应像素值
107 | */
108 | public static int getDimen(int id) {
109 | return getContext().getResources().getDimensionPixelSize(id);// 返回具体像素值
110 | }
111 |
112 | /**
113 | * 将px值转换为dip或dp值,保证尺寸大小不变
114 | *
115 | * @param pxValue
116 | * @return
117 | */
118 | public static int px2dip(float pxValue) {
119 | final float scale = getContext().getResources().getDisplayMetrics().density;
120 | return (int) (pxValue / scale + 0.5f);
121 | }
122 |
123 | /**
124 | * 将dip或dp值转换为px值,保证尺寸大小不变
125 | *
126 | * @param dipValue
127 | * @return
128 | */
129 | public static int dip2px(float dipValue) {
130 | final float scale = getContext().getResources().getDisplayMetrics().density;
131 | return (int) (dipValue * scale + 0.5f);
132 | }
133 |
134 | /**
135 | * 将px值转换为sp值,保证文字大小不变
136 | *
137 | * @param pxValue
138 | * @return
139 | */
140 | public static int px2sp(float pxValue) {
141 | final float fontScale = getContext().getResources().getDisplayMetrics().scaledDensity;
142 | return (int) (pxValue / fontScale + 0.5f);
143 | }
144 |
145 | /**
146 | * 将px值转换为sp值,保证文字大小不变
147 | *
148 | * @param spValue
149 | * @return
150 | */
151 | public static int sp2px(float spValue) {
152 | final float fontScale = getContext().getResources().getDisplayMetrics().scaledDensity;
153 | return (int) (spValue * fontScale + 0.5f);
154 | }
155 |
156 | /**
157 | * 加载布局文件
158 | *
159 | * @param id 布局文件id
160 | * @return 布局view
161 | */
162 | public static View inflate(int id) {
163 | return View.inflate(getContext(), id, null);
164 | }
165 |
166 | /**
167 | * 判断是否运行在主线程
168 | *
169 | * @return true:当前线程运行在主线程
170 | * fasle:当前线程没有运行在主线程
171 | */
172 | public static boolean isRunOnUIThread() {
173 | // 获取当前线程id, 如果当前线程id和主线程id相同, 那么当前就是主线程
174 | int myTid = android.os.Process.myTid();
175 | if (myTid == getMainThreadId()) {
176 | return true;
177 | }
178 | return false;
179 | }
180 |
181 | /**
182 | * 运行在主线程
183 | *
184 | * @param r 运行的Runnable对象
185 | */
186 | public static void runOnUIThread(Runnable r) {
187 | if (isRunOnUIThread()) {
188 | // 已经是主线程, 直接运行
189 | r.run();
190 | } else {
191 | // 如果是子线程, 借助handler让其运行在主线程
192 | getHandler().post(r);
193 | }
194 | }
195 |
196 | /**
197 | * 获取状态栏高度
198 | *
199 | * @param v view
200 | * @return 状态栏高度
201 | */
202 | public static int getStatusBarHeight(View v) {
203 | if (v == null) {
204 | return 0;
205 | }
206 | Rect frame = new Rect();
207 | v.getWindowVisibleDisplayFrame(frame);
208 | return frame.top;
209 | }
210 |
211 | /**
212 | * 设置状态栏背景色
213 | * 4.4以下不处理
214 | * 4.4使用默认沉浸式状态栏
215 | *
216 | * @param color 要为状态栏设置的颜色值
217 | */
218 | public static void setBarColor(Activity activity, int color) {
219 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
220 | Window win = activity.getWindow();
221 | View decorView = win.getDecorView();
222 | win.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//沉浸式状态栏
223 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//android5.0及以上才有透明效果
224 | win.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//清除flag
225 | //让应用的主体内容占用系统状态栏的空间
226 | int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
227 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
228 | decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | option);
229 | win.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
230 | win.setStatusBarColor(color);//设置状态栏背景色
231 | }
232 | }
233 | }
234 |
235 | /**
236 | * 获取APP版本号
237 | */
238 | public static String getAppVersion() {
239 | String version = null;
240 | try {
241 | PackageInfo info = getContext().getPackageManager().getPackageInfo
242 | (getContext().getPackageName(), 0);
243 | version = info.versionName;
244 | } catch (PackageManager.NameNotFoundException e) {
245 | e.printStackTrace();
246 | }
247 | return version;
248 | }
249 | }
250 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/nestingrecyclerviewdemo/ui/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.nestingrecyclerviewdemo.ui;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.View;
8 | import android.widget.Button;
9 |
10 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.R;
11 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.adapter.DemoAdapter;
12 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.adapter.OnCheckChangeListener;
13 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.bean.ChildItemBean;
14 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.bean.DemoItemBean;
15 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.bean.GroupItemBean;
16 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.helper.ParseHelper;
17 |
18 | import java.util.List;
19 |
20 | public class MainActivity extends AppCompatActivity {
21 |
22 | private RecyclerView rvNestDemo;
23 | private DemoAdapter mDemoAdapter;
24 | private List mDatas;
25 | private Button btnDelete, btnAddGroup, btnAddNormal, btnChild;
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_main);
31 | initData();
32 | initView();
33 | }
34 |
35 | private void initData() {
36 | mDatas = ParseHelper.getParseDatas();
37 | }
38 |
39 | private void initView() {
40 | rvNestDemo = (RecyclerView) findViewById(R.id.rv_nest_demo);
41 | btnDelete = (Button) findViewById(R.id.btn_delete);
42 | btnAddGroup = (Button) findViewById(R.id.btn_add_group);
43 | btnAddNormal = (Button) findViewById(R.id.btn_add_normal);
44 | btnChild = (Button) findViewById(R.id.btn_add_child);
45 |
46 | rvNestDemo.setLayoutManager(new LinearLayoutManager(this));
47 | mDemoAdapter = new DemoAdapter(this, mDatas);
48 | mDemoAdapter.setOnCheckChangeListener(new OnCheckChangeListener() {
49 | @Override
50 | public void onCheckedChanged(List beans, int position, boolean
51 | isChecked, int itemType) {
52 | switch (itemType) {
53 | case DemoItemBean.TYPE_NORMAL:
54 | normalCheckChange(beans, position, isChecked);
55 | break;
56 | case DemoItemBean.TYPE_GROUP:
57 | groupCheckChange(beans, position, isChecked);
58 | break;
59 | case DemoItemBean.TYPE_CHILD:
60 | childCheckChange(beans, position, isChecked);
61 | break;
62 | }
63 | }
64 | });
65 | rvNestDemo.setAdapter(mDemoAdapter);
66 |
67 | btnDelete.setOnClickListener(new OnClickListener());
68 | btnAddGroup.setOnClickListener(new OnClickListener());
69 | btnAddNormal.setOnClickListener(new OnClickListener());
70 | btnChild.setOnClickListener(new OnClickListener());
71 | }
72 |
73 | /**
74 | * normal选中状态变化
75 | *
76 | * @param beans 数据
77 | * @param position group position
78 | * @param isChecked 选中状态
79 | */
80 | private void normalCheckChange(List beans, int position, boolean isChecked) {
81 | if (rvNestDemo.getScrollState() == RecyclerView.SCROLL_STATE_IDLE
82 | && !rvNestDemo.isComputingLayout()) {//避免滑动时刷新数据
83 | beans.get(position).setChecked(isChecked);
84 | }
85 | }
86 |
87 | /**
88 | * group选中状态变化
89 | *
90 | * @param beans 数据
91 | * @param position group position
92 | * @param isChecked 选中状态
93 | */
94 | private void groupCheckChange(List beans, int position, boolean isChecked) {
95 | if (rvNestDemo.getScrollState() == RecyclerView.SCROLL_STATE_IDLE
96 | && !rvNestDemo.isComputingLayout()) {//避免滑动时刷新数据
97 | beans.get(position).setChecked(isChecked);
98 | setChildCheck(beans, position, isChecked);
99 | }
100 | }
101 |
102 | /**
103 | * child选中状态变化
104 | *
105 | * @param beans 数据
106 | * @param position child position
107 | * @param isChecked 选中状态
108 | */
109 | private void childCheckChange(List beans, int position, boolean isChecked) {
110 | int itemId = beans.get(position).getItemId();
111 |
112 | if (rvNestDemo.getScrollState() == RecyclerView.SCROLL_STATE_IDLE
113 | && !rvNestDemo.isComputingLayout()) {//避免滑动时刷新数据
114 |
115 | beans.get(position).setChecked(isChecked);
116 |
117 | GroupItemBean groupBean = ParseHelper.getGroupBean(beans, itemId);
118 |
119 | List childList = ParseHelper.getChildList(beans, position);
120 | for (int i = 0; i < childList.size(); i++) {
121 | if (!childList.get(i).isChecked()) {//只要有一个child没有选中,group就不是选中
122 | if (groupBean.isChecked() && !isChecked) {//group为选中状态
123 | setGroupCheck(beans, itemId, false);
124 | mDemoAdapter.notifyItemChanged(ParseHelper.getGroupPosition(beans,
125 | itemId));
126 | }
127 | return;
128 | }
129 | }
130 |
131 | //child全部选中,group设置选中
132 | setGroupCheck(beans, itemId, true);
133 | mDemoAdapter.notifyItemChanged(ParseHelper.getGroupPosition(beans, itemId));
134 | }
135 | }
136 |
137 | /**
138 | * 一次设置group下所有child item选中状态
139 | *
140 | * @param beans 整个数据list
141 | * @param position group position
142 | * @param isChecked 设置选中状态
143 | */
144 | private void setChildCheck(List beans, int position, boolean isChecked) {
145 | for (int i = 0; i < beans.size(); i++) {
146 | //item id不相同直接跳过
147 | if (beans.get(i).getItemId() != beans.get(position).getItemId())
148 | continue;
149 |
150 | if (beans.get(i).getItemType() == DemoItemBean.TYPE_CHILD) {//让group下的所有child选中
151 | if (beans.get(i).isChecked() != isChecked) {
152 | beans.get(i).setChecked(isChecked);
153 | mDemoAdapter.notifyItemChanged(i);
154 | }
155 | }
156 | }
157 | }
158 |
159 | /**
160 | * 设置group item选中状态
161 | *
162 | * @param beans 整个数据list
163 | * @param itemId child的itemId
164 | * @param isChecked 设置选中状态
165 | */
166 | private void setGroupCheck(List beans, int itemId, boolean isChecked) {
167 | for (DemoItemBean bean : beans) {
168 | if (bean.getItemType() == DemoItemBean.TYPE_GROUP
169 | && bean.getItemId() == itemId) {
170 | bean.setChecked(isChecked);
171 | }
172 | }
173 | }
174 |
175 | private class OnClickListener implements View.OnClickListener {
176 | @Override
177 | public void onClick(View v) {
178 | switch (v.getId()) {
179 | case R.id.btn_add_normal:
180 | mDemoAdapter.addNormal();
181 | rvNestDemo.smoothScrollToPosition(mDemoAdapter.getLastNormalItemPosition());
182 | break;
183 | case R.id.btn_add_group:
184 | mDemoAdapter.addGroup();
185 | rvNestDemo.smoothScrollToPosition(mDemoAdapter.getLastItemPosition());
186 | break;
187 | case R.id.btn_add_child:
188 | mDemoAdapter.addChild();
189 | rvNestDemo.smoothScrollToPosition(mDemoAdapter.getLastItemPosition());
190 | break;
191 | case R.id.btn_delete:
192 | mDemoAdapter.removeChecked();
193 | break;
194 | }
195 | }
196 | }
197 | }
198 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/nestingrecyclerviewdemo/adapter/DemoAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.nestingrecyclerviewdemo.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.util.Log;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.CompoundButton;
10 |
11 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.R;
12 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.adapter.ViewHolder.ChildViewHolder;
13 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.adapter.ViewHolder.GroupViewHolder;
14 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.adapter.ViewHolder.NormalViewHolder;
15 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.bean.ChildItemBean;
16 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.bean.DemoItemBean;
17 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.bean.GroupItemBean;
18 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.bean.NormalItemBean;
19 | import com.zyw.horrarndoo.nestingrecyclerviewdemo.helper.ParseHelper;
20 |
21 | import java.util.List;
22 |
23 | /**
24 | * Created by Horrarndoo on 2017/11/22.
25 | *
26 | */
27 |
28 | public class DemoAdapter extends RecyclerView.Adapter {
29 |
30 | private List mDatas;
31 | private Context mContext;
32 | private OnCheckChangeListener onCheckChangeListener;
33 |
34 | public void setOnCheckChangeListener(OnCheckChangeListener l) {
35 | onCheckChangeListener = l;
36 | }
37 |
38 | public DemoAdapter(Context context, List datas) {
39 | mContext = context;
40 | mDatas = datas;
41 | }
42 |
43 | @Override
44 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
45 | Log.w("tag", "onCreateViewHolder");
46 | LayoutInflater mInflater = LayoutInflater.from(mContext);
47 | RecyclerView.ViewHolder holder = null;
48 | switch (viewType) {
49 | case DemoItemBean.TYPE_NORMAL:
50 | View v = mInflater.inflate(R.layout.item_normal, parent, false);
51 | holder = new NormalViewHolder(v);
52 | break;
53 | case DemoItemBean.TYPE_GROUP:
54 | View v1 = mInflater.inflate(R.layout.item_group, parent, false);
55 | holder = new GroupViewHolder(v1);
56 | break;
57 | case DemoItemBean.TYPE_CHILD:
58 | View v2 = mInflater.inflate(R.layout.item_child, parent, false);
59 | holder = new ChildViewHolder(v2);
60 | break;
61 | }
62 | return holder;
63 | }
64 |
65 | @Override
66 | public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
67 | Log.w("tag", "onBindViewHolder");
68 | if (holder instanceof NormalViewHolder) {
69 | NormalViewHolder nHolder = (NormalViewHolder) holder;
70 | nHolder.bindData((NormalItemBean) mDatas.get(position));
71 | nHolder.tvNormal.setText(mDatas.get(position).getTitle());
72 | nHolder.cbNormal.setOnCheckedChangeListener(new OnCheckedChangeListener(position,
73 | DemoItemBean.TYPE_NORMAL));
74 | nHolder.cbNormal.setChecked(mDatas.get(position).isChecked());
75 | } else if (holder instanceof GroupViewHolder) {
76 | GroupViewHolder gHolder = (GroupViewHolder) holder;
77 | gHolder.bindData((GroupItemBean) mDatas.get(position));
78 | gHolder.tvGroup.setText(mDatas.get(position).getTitle());
79 | gHolder.cbGroup.setOnCheckedChangeListener(new OnCheckedChangeListener(position,
80 | DemoItemBean.TYPE_GROUP));
81 | gHolder.cbGroup.setChecked(mDatas.get(position).isChecked());
82 | } else if (holder instanceof ChildViewHolder) {
83 | ChildViewHolder cHolder = (ChildViewHolder) holder;
84 | cHolder.bindData((ChildItemBean) mDatas.get(position));
85 | cHolder.tvChild.setText(mDatas.get(position).getTitle());
86 | cHolder.cbChild.setOnCheckedChangeListener(new OnCheckedChangeListener(position,
87 | DemoItemBean.TYPE_CHILD));
88 | cHolder.cbChild.setChecked(mDatas.get(position).isChecked());
89 | }
90 | }
91 |
92 | @Override
93 | public int getItemViewType(int position) {
94 | return mDatas.get(position).getItemType();
95 | }
96 |
97 | @Override
98 | public int getItemCount() {
99 | return mDatas.size();
100 | }
101 |
102 | /**
103 | * CheckBox CheckedChangeListener
104 | */
105 | private class OnCheckedChangeListener implements CompoundButton.OnCheckedChangeListener {
106 | int mPosition, mItemType;
107 |
108 | public OnCheckedChangeListener(int position, int itemType) {
109 | mPosition = position;
110 | mItemType = itemType;
111 | }
112 |
113 | @Override
114 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
115 | if (onCheckChangeListener != null)
116 | onCheckChangeListener.onCheckedChanged(mDatas, mPosition, isChecked, mItemType);
117 | }
118 | }
119 |
120 | /**
121 | * 删除选中item
122 | */
123 | public void removeChecked() {
124 | int iMax = mDatas.size() - 1;
125 | //这里要倒序,因为要删除mDatas中的数据,mDatas的长度会变化
126 | for (int i = iMax; i >= 0; i--) {
127 | if (mDatas.get(i).isChecked()) {
128 | mDatas.remove(i);
129 | notifyItemRemoved(i);
130 | notifyItemRangeChanged(i, mDatas.size());
131 | }
132 | }
133 | }
134 |
135 | /**
136 | * 添加 Normal item
137 | */
138 | public void addNormal() {
139 | int addPosition = 0;
140 | int itemId = 0;
141 | for (int i = 0; i < mDatas.size(); i++) {
142 | if (mDatas.get(i).getItemType() == DemoItemBean.TYPE_GROUP) {
143 | addPosition = i;//得到要插入的position
144 | break;
145 | }
146 | }
147 |
148 | if (!isHaveGroup()) {//如果列表中没有group,直接在list末尾添加item
149 | if (addPosition == 0) {
150 | addPosition = mDatas.size();
151 | }
152 | }
153 |
154 | if (addPosition > 0) {
155 | itemId = mDatas.get(addPosition - 1).getItemId() + 1;
156 | }
157 |
158 | mDatas.add(addPosition, ParseHelper.newNormalItem(itemId));
159 | notifyItemInserted(addPosition);//通知演示插入动画
160 | notifyItemRangeChanged(addPosition, mDatas.size() - addPosition);//通知数据与界面重新绑定
161 | }
162 |
163 | /**
164 | * 添加 Group item
165 | */
166 | public void addGroup() {
167 | int addPosition = mDatas.size();
168 | int itemId = 0;
169 |
170 | if (isHaveGroup()) {
171 | for (int i = 0; i < mDatas.size(); i++) {
172 | if (mDatas.get(i).getItemType() == DemoItemBean.TYPE_GROUP) {
173 | itemId = mDatas.get(i).getItemId() + 1;
174 | }
175 | }
176 | }
177 |
178 | mDatas.add(addPosition, ParseHelper.newGroupItem(itemId));
179 | notifyItemInserted(addPosition);//通知演示插入动画
180 | notifyItemRangeChanged(addPosition, mDatas.size() - addPosition);//通知数据与界面重新绑定
181 | }
182 |
183 | /**
184 | * 添加 Child item
185 | *
186 | * child item添加位置永远归属于最后一个Group item
187 | */
188 | public void addChild() {
189 | int addPosition = 0;
190 | int itemId = 0;
191 | int childId = 0;
192 |
193 | if (!isHaveGroup() || mDatas.get(mDatas.size() - 1).getItemType() == DemoItemBean
194 | .TYPE_NORMAL) {
195 | addGroup();
196 | }
197 |
198 | for (int i = 0; i < mDatas.size(); i++) {
199 | if (mDatas.get(i).getItemType() == DemoItemBean.TYPE_GROUP) {
200 | itemId = mDatas.get(i).getItemId();
201 | }
202 | }
203 |
204 | for (int i = 0; i < mDatas.size(); i++) {
205 | if (mDatas.get(i).getItemId() == itemId && mDatas.get(i).getItemType() ==
206 | DemoItemBean.TYPE_CHILD) {
207 | childId++;
208 | }
209 | }
210 |
211 | addPosition = mDatas.size();
212 | mDatas.add(addPosition, ParseHelper.newChildItem(mDatas, itemId, childId));
213 | notifyItemInserted(addPosition);//通知演示插入动画
214 | notifyItemRangeChanged(addPosition, mDatas.size() - addPosition);//通知数据与界面重新绑定
215 |
216 | if (onCheckChangeListener != null)
217 | onCheckChangeListener.onCheckedChanged(mDatas, addPosition, mDatas.get(addPosition)
218 | .isChecked(), DemoItemBean.TYPE_CHILD);
219 | }
220 |
221 | /**
222 | * 当前list是否含有group
223 | *
224 | * @return 当前list是否含有group
225 | */
226 | private boolean isHaveGroup() {
227 | boolean isHaveGroup = false;//当前列表是否包含group
228 |
229 | for (int i = 0; i < mDatas.size(); i++) {
230 | if (mDatas.get(i).getItemType() == DemoItemBean.TYPE_GROUP) {
231 | isHaveGroup = true;
232 | break;
233 | }
234 | }
235 | return isHaveGroup;
236 | }
237 |
238 | /**
239 | * 获取最后一个Normal item的position
240 | *
241 | * @return 最后一个Normal item的position
242 | */
243 | public int getLastNormalItemPosition() {
244 | int addPosition = 0;
245 | for (int i = 0; i < mDatas.size(); i++) {
246 | if (mDatas.get(i).getItemType() == DemoItemBean.TYPE_GROUP) {
247 | addPosition = i;
248 | break;
249 | }
250 | }
251 |
252 | if (addPosition == 0) {
253 | addPosition = mDatas.size();
254 | }
255 |
256 | return addPosition - 1;
257 | }
258 |
259 | /**
260 | * 获取最后一个item的position
261 | *
262 | * @return 最后一个item的position
263 | */
264 | public int getLastItemPosition() {
265 | return mDatas.size();
266 | }
267 | }
268 |
--------------------------------------------------------------------------------