recyclerview with multiple view types example 로 검색하면 검색되는 게시글이 https://hashcode.co.kr/questions/561/recyclerview%EC%97%90-%EC%97%AC%EB%9F%AC%EA%B0%9C%EC%9D%98-%EB%B7%B0%ED%83%80%EC%9E%85%EC%9D%84-%EB%84%A3%EC%9D%84-%EC%88%98-%EC%9E%88%EC%9D%84%EA%B9%8C%EC%9A%94 로 나온다.
이와 비슷한 답변이 여기저기 검색된다. 나같은 초보한테는 전혀 도움이 안된다.
완성된 예제 코드를 봐야 약간 활용할 수 있게 된다.
https://www.loopwiki.com/ui-ux-design/recyclerview-with-header-and-footer-android-example/
http://www.sunilandroid.com/2016/11/multiple-view-type-in-recyclerview-in.html
https://guides.codepath.com/android/Heterogenous-Layouts-inside-RecyclerView
직접 테스트해본 것은 아니지만 괜찮은 코드로 보인다.
http://www.codexpedia.com/android/android-recyclerview-with-multiple-different-layouts/
이 게시글을 참조하고 나서 원하는 결과를 구현할 수 있었다.
코드를 구현하면서 Type_1, Type_2 가 서로 내용이 다르고, 서버에서 가져올 데이터의 코드도 서로 상이하여 고민이 많았다.
하지만 이런 코드를 검색하면서 ArrayList 는 1개로 통일하여 설계를 하고 Class 를 만들어야 한다는 점이다.
서버에서 가져올 코드에서 최대한 일치할 수 있는 것을 일치하고 없는 칼럼은 공백으로 저장을 하더라도 하나의 규격으로 Class를 만들어서 활용하면 View Type 를 서로 다르게 보여주는 것이 가능하다.
테스트에 사용된 dependencies 는 아래와 같다.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.loopj.android:android-async-http:1.4.9' // 서버와의 통신 라이브러리
implementation 'com.github.bumptech.glide:glide:3.8.0' // 이미지 라이브러리
implementation 'com.android.support:recyclerview-v7:24.2.0' // ListView 개선 버전
implementation "com.android.support:cardview-v7:24.2.0"
} ===> Android Studio 3.1.3
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.loopj.android:android-async-http:1.4.9' // 서버와의 통신 라이브러리
compile 'com.github.bumptech.glide:glide:3.8.0' // 이미지 라이브러리
compile 'com.android.support:recyclerview-v7:24.2.0' // ListView 개선 버전
compile "com.android.support:cardview-v7:24.2.0"
} ===> Android Studio 2.3.3
'안드로이드 > ListView, RecyclerView' 카테고리의 다른 글
RecyclerView Checkbox 처리 및 Interface 처리 (0) | 2020.07.17 |
---|---|
RecyclerViewAdapter 만드는 방법 (0) | 2018.10.05 |
support.v7.widget.CardView (1) | 2018.07.23 |
안드로이드 스튜디오 체크박스 있는 Custom ListView 에서 RecyclerView 로 코드 수정부분 비교 (0) | 2017.10.13 |
Android Custom ListView Checkbox 처리 (0) | 2017.05.06 |