DB에서 CursorAapdater를 통해 이미지를 가져올 수 있는 경우가 아니라면, 별도로 어댑터를 만드셔야 합니다. 레이아웃에 RecyclerView 갖다놓고 Recycler.Adapter를 구현하시면 됩니다. Recycler.Adapter에 화면에 보여지길 원하는 아이템을 List로 만드신 다음 이걸 Recycler.Adapter 전달해 주시면 됩니다. RecyclerView에 대한 튜토리얼은 너무 넘쳐나서 코드를 반복하지는 않겠습니다.
https://developer.android.com/guide/topics/ui/layout/recyclerview?gclid=CjwKCAjwz5iMBhAEEiwAMEAwGPE0RF9kHaJEVNFBXeoSPWd_qzgjkxlmWZSaHO9mU0BrGTxCPY7uphoCj4wQAvD_BwE&gclsrc=aw.ds
위의 링크에 보시면 개발자 문서에 자세한 안내가 나와있고, 페이지 하단에 샘플 코드 링크가 있습니다. (한글 번역판도 있는 것으로 압니다.)
구글에서 Android RecyclerView로 검색하시면 아주 많은 검색결과가 나올 겁니다. 적당한 걸 골라서 확인해 보세요.
참고로 님의 경우는 db 에서 데이터를 가져와서 images와 함께 데이터를 조합해서 만드셔야 합니다. 어떻게 데이터 변환을 하는지 간단한 예제를 올릴게요. (이미지를 올리셔서 코드 카피가 안되네요.)
//Movie.java
// 필드 타입을 알 수 없어서 그냥 int로 함.
public class Movie {
pirvate final int id;
private final String title;
private final Int rating;
private final String genre;
private final String year;
@DrawableRes private final int imageId;
// Constructor, getters, setters 생략
}
// MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) [
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
helper = new DBHelper(this);
db = helper.getWritableDatase();
Cursor c = db.query(...);
// 여기서부터 DB데이터를 RecyclerView에 사용할 수 있도록 변환하는 코드
List<Movie> movies = new ArrayList<>();
if (c.moveToFirst()) {
do {
int id = c.getInt(1);
String title = c.getString(2);
int rating = c.getInt(3);
Stirng genre = c.getString(4);
String year = c.getString(5);
// DB에 들어있는 영화 정보에 맞는 이미지의 리소스 ID를 가져옴. 여기에 대한 규칙은 님만 알고 있어요.
int imageId = getMovieImageId(...);
Moview movie = new Movie(id, title, rating, genre, year, imageId);
movies.add(movie);
} while(cr.moveToNext());
}
// 여기에서 공부하실 RecyclerView에 대한 지식을 가지고 RecyclerView.Adapter에 movies를 전달해주면 됩니다.
}
// 님만이 이미지 리소스와 DB에 들어있는 영화정보에 대한 매핑을 할 수 있기 때문에 파라미터들과 내부 로직은 비워둡니다.
// 현재로썬 이 부분에 대해서는 제가 도와드릴 수 있는 정보가 없어요.
private int getMovieImageId() {
// 구현필요.
}
}