├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── developer │ │ └── solutions │ │ └── recyclerviewwithmultipleviewtype │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── developer │ │ │ └── solutions │ │ │ └── recyclerviewwithmultipleviewtype │ │ │ ├── activity │ │ │ └── MainActivity.java │ │ │ ├── adapter │ │ │ ├── MultiViewTypeAdapter.java │ │ │ └── SliderPagerAdapter.java │ │ │ └── model │ │ │ └── Data.java │ └── res │ │ ├── drawable │ │ ├── disneys_cinderella.jpg │ │ └── snow.png │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── item_button_type.xml │ │ ├── item_image_type.xml │ │ ├── layout_slider.xml │ │ └── viewpager.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── screenshot │ │ ├── device-2017-08-28-131636.png │ │ └── device-2017-08-28-131741.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── developer │ └── solutions │ └── recyclerviewwithmultipleviewtype │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/dictionaries 41 | .idea/libraries 42 | 43 | # Keystore files 44 | *.jks 45 | 46 | # External native build folder generated in Android Studio 2.2 and later 47 | .externalNativeBuild 48 | 49 | # Google Services (e.g. APIs or Firebase) 50 | google-services.json 51 | 52 | # Freeline 53 | freeline.py 54 | freeline/ 55 | freeline_project_description.json 56 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RecyclerViewWIthMultipleViewType 2 | Binding Recycler View with multiple view type , for complete tutorial 3 | check below link www.androiddevelopersolutions.com 4 | 5 | ![alt text](https://raw.githubusercontent.com/mukesh4u/RecyclerViewWIthMultipleViewType/master/app/src/main/res/screenshot/device-2017-08-28-131636.png) 6 | ![alt text](https://raw.githubusercontent.com/mukesh4u/RecyclerViewWIthMultipleViewType/master/app/src/main/res/screenshot/device-2017-08-28-131741.png) 7 | 8 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "android.developer.solutions.recyclerviewwithmultipleviewtype" 8 | minSdkVersion 14 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | debuggable false 17 | minifyEnabled true 18 | shrinkResources true 19 | zipAlignEnabled true 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | debug { 23 | debuggable false 24 | minifyEnabled true 25 | shrinkResources true 26 | zipAlignEnabled true 27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 28 | } 29 | } 30 | } 31 | 32 | dependencies { 33 | compile fileTree(dir: 'libs', include: ['*.jar']) 34 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 35 | exclude group: 'com.android.support', module: 'support-annotations' 36 | }) 37 | compile 'com.android.support:appcompat-v7:25.3.0' 38 | compile 'com.android.support:design:25.3.0' 39 | compile 'com.android.support:cardview-v7:25.3.0' 40 | testCompile 'junit:junit:4.12' 41 | compile 'com.jakewharton:butterknife:8.7.0' 42 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0' 43 | compile 'com.squareup.picasso:picasso:2.5.2' 44 | } 45 | -------------------------------------------------------------------------------- /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 /home/mukesh/Documents/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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | 27 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# 28 | #-------------------------------- GENERIC PROGUARD CONFIGURATION ----------------------------------# 29 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# 30 | 31 | -optimizationpasses 5 32 | -dontusemixedcaseclassnames 33 | -dontskipnonpubliclibraryclasses 34 | -dontskipnonpubliclibraryclassmembers 35 | -dontpreverify 36 | -verbose 37 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!code/allocation/variable,!class/unboxing/enum 38 | 39 | -renamesourcefileattribute SourceFile 40 | -keepattributes SourceFile,LineNumberTable 41 | 42 | -keep class android.content.pm.PackageInstaller 43 | -keep class android.content.pm.PackageInstaller$SessionInfo 44 | -keep class android.content.pm.PackageManager 45 | -keep class android.webkit.WebSettings 46 | -keep class android.os.Message 47 | 48 | -dontwarn android.content.pm.PackageInstaller 49 | -dontwarn android.content.pm.PackageInstaller$SessionInfo 50 | -dontwarn android.content.pm.PackageManager 51 | -dontwarn com.google.android.gms.* 52 | -dontwarn android.webkit.WopwebSettings 53 | -dontwarn android.os.Message 54 | -dontwarn sun.misc.Unsafe 55 | -dontwarn sun.reflect.** 56 | 57 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# 58 | #----------------------------------- ANDROID SUPPORT LIBRARY --------------------------------------# 59 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# 60 | -dontwarn android.support.** 61 | 62 | -keep class android.support.v4.** { *; } 63 | 64 | -dontwarn android.support.v7.** 65 | -keep class android.support.v7.** { *; } 66 | -keep interface android.support.v7.** { *; } 67 | 68 | -dontwarn android.support.design.** 69 | -keep class android.support.design.** { *; } 70 | -keep interface android.support.design.** { *; } 71 | -keep public class android.support.design.R$* { *; } 72 | 73 | 74 | # Preserve all classes that have special context constructors, and the 75 | # constructors themselves. 76 | -keepclasseswithmembers class * { 77 | public (android.content.Context, android.util.AttributeSet); 78 | } 79 | 80 | # Preserve all classes that have special context constructors, and the 81 | # constructors themselves. 82 | -keepclasseswithmembers class * { 83 | public (android.content.Context, android.util.AttributeSet, int); 84 | } 85 | 86 | -keepclassmembers class * extends android.app.Activity { 87 | public void *(android.view.View); 88 | } 89 | 90 | # Preserve the special static methods that are required in all enumeration 91 | # classes. 92 | -keepclassmembers,allowoptimization enum * { 93 | public static **[] values(); 94 | public static ** valueOf(java.lang.String); 95 | } 96 | 97 | 98 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# 99 | #--------------------------------------- ANDROID SDK ----------------------------------------------# 100 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# 101 | -keep public class * extends android.app.Activity 102 | -keep public class * extends android.app.Application 103 | -keep public class * extends android.app.Service 104 | -keep public class * extends android.preference.Preference 105 | -keep public class android.app.IntentService 106 | -keep public class * extends android.content.BroadcastReceiver 107 | -keep public class * extends android.content.ContentProvider 108 | -keep public class * extends android.widget.BaseAdapter 109 | 110 | #USED FOR OS API ABOVE 17 111 | -keepattributes JavascriptInterface 112 | -keepattributes *Annotation* 113 | 114 | -dontwarn android.app.** 115 | -dontwarn android.view.** 116 | -dontwarn android.widget.** 117 | 118 | -dontwarn **CompatHoneycomb 119 | -dontwarn **CompatHoneycombMR2 120 | -dontwarn **CompatCreatorHoneycombMR2 121 | 122 | -keepclasseswithmembernames class * { 123 | native ; 124 | } 125 | 126 | -keepclasseswithmembers class * { 127 | public (android.content.Context, android.util.AttributeSet); 128 | } 129 | 130 | -keepclasseswithmembers class * { 131 | public (android.content.Context, android.util.AttributeSet, int); 132 | } 133 | 134 | -keep public class * extends android.view.View { 135 | public (android.content.Context); 136 | public (android.content.Context, android.util.AttributeSet); 137 | public (android.content.Context, android.util.AttributeSet, int); 138 | public void set*(...); 139 | } 140 | 141 | -keepclassmembers class * extends android.content.Context { 142 | public void *(android.view.View); 143 | public void *(android.view.MenuItem); 144 | } 145 | 146 | -keepnames class * implements android.os.Parcelable { 147 | public static final ** CREATOR; 148 | } 149 | 150 | -keepclassmembers class **.R$* { 151 | public static ; 152 | } 153 | 154 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# 155 | #--------------------------------------------- Picasso --------------------------------------------# 156 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 157 | -dontwarn com.squareup.okhttp.** -------------------------------------------------------------------------------- /app/src/androidTest/java/com/developer/solutions/recyclerviewwithmultipleviewtype/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.developer.solutions.recyclerviewwithmultipleviewtype; 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("android.developer.solutions.recyclerviewwithmultipleviewtype", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/developer/solutions/recyclerviewwithmultipleviewtype/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.developer.solutions.recyclerviewwithmultipleviewtype.activity; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Binder; 6 | import android.os.Bundle; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.support.v7.widget.DefaultItemAnimator; 9 | import android.support.v7.widget.LinearLayoutCompat; 10 | import android.support.v7.widget.LinearLayoutManager; 11 | import android.support.v7.widget.OrientationHelper; 12 | import android.support.v7.widget.RecyclerView; 13 | import android.support.v7.widget.Toolbar; 14 | import android.widget.TextView; 15 | 16 | import com.developer.solutions.recyclerviewwithmultipleviewtype.R; 17 | import com.developer.solutions.recyclerviewwithmultipleviewtype.adapter.MultiViewTypeAdapter; 18 | import com.developer.solutions.recyclerviewwithmultipleviewtype.model.Data; 19 | 20 | import java.util.ArrayList; 21 | 22 | import butterknife.BindView; 23 | import butterknife.ButterKnife; 24 | import butterknife.Unbinder; 25 | 26 | /** 27 | * Created by Mukesh on 3/8/17. 28 | * himky02@gmail.com 29 | */ 30 | public class MainActivity extends AppCompatActivity { 31 | 32 | Activity mActivity; 33 | @BindView(R.id.toolbar) 34 | Toolbar toolbar; 35 | @BindView(R.id.rv) 36 | RecyclerView mRecyclerView; 37 | Unbinder mUnbinder; 38 | 39 | 40 | @Override 41 | protected void onCreate(Bundle savedInstanceState) { 42 | super.onCreate(savedInstanceState); 43 | setContentView(R.layout.activity_main); 44 | //((TextView) findViewById(R.id.tv)).setText("Welcome user"); 45 | mUnbinder = ButterKnife.bind(this); 46 | 47 | ArrayList list = new ArrayList<>(); 48 | list.add(new Data(Data.VIEW_PAGER, "Hello. This is the View Pager view type with images", 0)); 49 | list.add(new Data(Data.IMAGE_TYPE, "A view type with Image and Textview", R.drawable.disneys_cinderella)); 50 | list.add(new Data(Data.AUDIO_TYPE, "Hey, A view type with Button and Textview", 0)); 51 | list.add(new Data(Data.IMAGE_TYPE, "Hi again. A view with Image and Textview", R.drawable.snow)); 52 | 53 | MultiViewTypeAdapter adapter = new MultiViewTypeAdapter(list, this); 54 | final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); 55 | linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); 56 | mRecyclerView.setLayoutManager(linearLayoutManager); 57 | mRecyclerView.setItemAnimator(new DefaultItemAnimator()); 58 | mRecyclerView.setAdapter(adapter); 59 | } 60 | 61 | @Override 62 | protected void onDestroy() { 63 | super.onDestroy(); 64 | if (mUnbinder != null) mUnbinder.unbind(); 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/developer/solutions/recyclerviewwithmultipleviewtype/adapter/MultiViewTypeAdapter.java: -------------------------------------------------------------------------------- 1 | package com.developer.solutions.recyclerviewwithmultipleviewtype.adapter; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.graphics.Color; 6 | import android.os.Handler; 7 | import android.support.v4.view.ViewPager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.text.Html; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.Button; 14 | import android.widget.ImageView; 15 | import android.widget.LinearLayout; 16 | import android.widget.TextView; 17 | import android.widget.Toast; 18 | 19 | import com.developer.solutions.recyclerviewwithmultipleviewtype.R; 20 | import com.developer.solutions.recyclerviewwithmultipleviewtype.model.Data; 21 | 22 | import java.util.ArrayList; 23 | 24 | import butterknife.BindView; 25 | import butterknife.ButterKnife; 26 | 27 | /** 28 | * Created by Mukesh on 3/8/17. 29 | * himky02@gmail.com 30 | */ 31 | public class MultiViewTypeAdapter extends RecyclerView.Adapter { 32 | private ArrayList dataSet; 33 | Context mContext; 34 | int total_types; 35 | ArrayList slider_image_list; 36 | int page = 0; 37 | 38 | public static class TextTypeViewHolder extends RecyclerView.ViewHolder { 39 | @BindView(R.id.ll_dots) 40 | LinearLayout ll_dots; 41 | @BindView(R.id.vp_slider) 42 | ViewPager mvViewPager; 43 | 44 | public TextTypeViewHolder(View itemView) { 45 | super(itemView); 46 | ButterKnife.bind(this, itemView); 47 | } 48 | } 49 | 50 | public static class ImageTypeViewHolder extends RecyclerView.ViewHolder { 51 | @BindView(R.id.type) 52 | TextView tvtype; 53 | @BindView(R.id.img) 54 | ImageView iv; 55 | 56 | public ImageTypeViewHolder(View itemView) { 57 | super(itemView); 58 | ButterKnife.bind(this, itemView); 59 | } 60 | } 61 | 62 | public static class ButtonTypeViewHolder extends RecyclerView.ViewHolder { 63 | @BindView(R.id.type) 64 | TextView type; 65 | @BindView(R.id.btn) 66 | Button btn; 67 | 68 | public ButtonTypeViewHolder(View itemView) { 69 | super(itemView); 70 | ButterKnife.bind(this, itemView); 71 | } 72 | } 73 | 74 | public MultiViewTypeAdapter(ArrayList data, Context context) { 75 | this.dataSet = data; 76 | this.mContext = context; 77 | total_types = dataSet.size(); 78 | } 79 | 80 | @Override 81 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 82 | 83 | View view; 84 | switch (viewType) { 85 | case Data.VIEW_PAGER: 86 | view = LayoutInflater.from(parent.getContext()).inflate(R.layout.viewpager, parent, false); 87 | return new TextTypeViewHolder(view); 88 | case Data.IMAGE_TYPE: 89 | view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_image_type, parent, false); 90 | return new ImageTypeViewHolder(view); 91 | case Data.AUDIO_TYPE: 92 | view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_button_type, parent, false); 93 | return new ButtonTypeViewHolder(view); 94 | } 95 | return null; 96 | 97 | 98 | } 99 | 100 | 101 | @Override 102 | public int getItemViewType(int position) { 103 | 104 | switch (dataSet.get(position).type) { 105 | case 0: 106 | return Data.VIEW_PAGER; 107 | case 1: 108 | return Data.IMAGE_TYPE; 109 | case 2: 110 | return Data.AUDIO_TYPE; 111 | default: 112 | return -1; 113 | } 114 | } 115 | 116 | @Override 117 | public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int listPosition) { 118 | 119 | Data object = dataSet.get(listPosition); 120 | if (object != null) { 121 | switch (object.type) { 122 | case Data.VIEW_PAGER: 123 | //((TextTypeViewHolder) holder).type.setText(object.text); 124 | slider_image_list = new ArrayList<>(); 125 | 126 | //Add few items to slider_image_list ,this should contain url of images which should be displayed in slider 127 | // here i am adding few sample image links, you can add your own 128 | 129 | slider_image_list.add("http://cdn.collider.com/wp-content/uploads/avengers-movie-banner-scarlett-johansson-jeremy-renner.jpg"); 130 | slider_image_list.add("http://www.officialterridwyer.com/wp-content/uploads/2015/04/Disneys-Cinderella-2015-Movie-Banner.jpg"); 131 | slider_image_list.add("http://igmedia.blob.core.windows.net/igmedia/hindi/gallery/movies/raabta/main1.jpg"); 132 | slider_image_list.add("http://fantoosy.com/wp-content/uploads/2015/11/tamasha.jpg"); 133 | final SliderPagerAdapter sliderPagerAdapter = new SliderPagerAdapter((Activity) mContext, slider_image_list); 134 | ((TextTypeViewHolder) holder).mvViewPager.setAdapter(sliderPagerAdapter); 135 | 136 | ((TextTypeViewHolder) holder).mvViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { 137 | @Override 138 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 139 | 140 | } 141 | 142 | @Override 143 | public void onPageSelected(int position) { 144 | addBottomDots(position, ((TextTypeViewHolder) holder).ll_dots); 145 | page = position; 146 | } 147 | 148 | @Override 149 | public void onPageScrollStateChanged(int state) { 150 | 151 | } 152 | }); 153 | addBottomDots(0, ((TextTypeViewHolder) holder).ll_dots); 154 | final Handler h = new Handler(); 155 | h.postDelayed(new Runnable() { 156 | @Override 157 | public void run() { 158 | if (sliderPagerAdapter.getCount() == page) { 159 | page = 0; 160 | } else { 161 | page++; 162 | } 163 | ((TextTypeViewHolder) holder).mvViewPager.setCurrentItem(page); 164 | h.postDelayed(this, 2000); 165 | } 166 | }, 1000); 167 | 168 | break; 169 | case Data.IMAGE_TYPE: 170 | ((ImageTypeViewHolder) holder).tvtype.setText(object.text); 171 | ((ImageTypeViewHolder) holder).iv.setImageResource(object.data); 172 | break; 173 | case Data.AUDIO_TYPE: 174 | ((ButtonTypeViewHolder) holder).type.setText(object.text); 175 | ((ButtonTypeViewHolder) holder).btn.setOnClickListener(new View.OnClickListener() { 176 | @Override 177 | public void onClick(View view) { 178 | Toast.makeText(mContext, "You clicked!!!", Toast.LENGTH_SHORT).show(); 179 | } 180 | }); 181 | break; 182 | } 183 | } 184 | 185 | } 186 | 187 | @Override 188 | public int getItemCount() { 189 | return dataSet.size(); 190 | } 191 | 192 | //showing dots on screen 193 | private void addBottomDots(int currentPage, LinearLayout ll_dots) { 194 | TextView[] dots = new TextView[slider_image_list.size()]; 195 | ll_dots.removeAllViews(); 196 | for (int i = 0; i < dots.length; i++) { 197 | dots[i] = new TextView(mContext); 198 | dots[i].setText(Html.fromHtml("•")); 199 | dots[i].setTextSize(35); 200 | dots[i].setTextColor(Color.parseColor("#343434")); 201 | ll_dots.addView(dots[i]); 202 | } 203 | 204 | if (dots.length > 0) 205 | dots[currentPage].setTextColor(Color.parseColor("#A2A2A2")); 206 | } 207 | 208 | } 209 | -------------------------------------------------------------------------------- /app/src/main/java/com/developer/solutions/recyclerviewwithmultipleviewtype/adapter/SliderPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.developer.solutions.recyclerviewwithmultipleviewtype.adapter; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.support.v4.view.PagerAdapter; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ImageView; 10 | 11 | import com.developer.solutions.recyclerviewwithmultipleviewtype.R; 12 | import com.squareup.picasso.Picasso; 13 | 14 | import java.util.ArrayList; 15 | 16 | /** 17 | * Created by Mukesh on 3/8/17. 18 | * himky02@gmail.com 19 | */ 20 | 21 | public class SliderPagerAdapter extends PagerAdapter { 22 | private LayoutInflater layoutInflater; 23 | Activity activity; 24 | ArrayList image_arraylist; 25 | 26 | public SliderPagerAdapter(Activity activity, ArrayList image_arraylist) { 27 | this.activity = activity; 28 | this.image_arraylist = image_arraylist; 29 | } 30 | 31 | @Override 32 | public Object instantiateItem(ViewGroup container, int position) { 33 | layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 34 | 35 | View view = layoutInflater.inflate(R.layout.layout_slider, container, false); 36 | ImageView im_slider = (ImageView) view.findViewById(R.id.im_slider); 37 | Picasso.with(activity.getApplicationContext()) 38 | .load(image_arraylist.get(position)) 39 | .placeholder(R.mipmap.ic_launcher) // optional 40 | .error(R.mipmap.ic_launcher) // optional 41 | .into(im_slider); 42 | 43 | 44 | container.addView(view); 45 | 46 | return view; 47 | } 48 | 49 | @Override 50 | public int getCount() { 51 | return image_arraylist.size(); 52 | } 53 | 54 | 55 | @Override 56 | public boolean isViewFromObject(View view, Object obj) { 57 | return view == obj; 58 | } 59 | 60 | 61 | @Override 62 | public void destroyItem(ViewGroup container, int position, Object object) { 63 | View view = (View) object; 64 | container.removeView(view); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /app/src/main/java/com/developer/solutions/recyclerviewwithmultipleviewtype/model/Data.java: -------------------------------------------------------------------------------- 1 | package com.developer.solutions.recyclerviewwithmultipleviewtype.model; 2 | 3 | /** 4 | * Created by Mukesh on 3/8/17. 5 | * himky02@gmail.com 6 | */ 7 | 8 | public class Data { 9 | public static final int VIEW_PAGER = 0; 10 | public static final int IMAGE_TYPE = 1; 11 | public static final int AUDIO_TYPE = 2; 12 | public int type; 13 | public int data; 14 | public String text; 15 | 16 | public Data(int type, String text, int data) { 17 | this.type = type; 18 | this.data = data; 19 | this.text = text; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/disneys_cinderella.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mukesh4u/RecyclerViewWIthMultipleViewType/8d9a8106dbe0b9a45321840357846bd4183ce5bd/app/src/main/res/drawable/disneys_cinderella.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/snow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mukesh4u/RecyclerViewWIthMultipleViewType/8d9a8106dbe0b9a45321840357846bd4183ce5bd/app/src/main/res/drawable/snow.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 21 | 22 | 23 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_button_type.xml: -------------------------------------------------------------------------------- 1 | 8 | 11 | 17 |