Develop/Android

[Android] RecyclerViewAdapter에서 Intent 호출

안다희 2019. 1. 25. 06:25
728x90
public RecyclerViewAdapter(Context mContext, List<BookInfo> BookInfoList)
{
    this.mContext = mContext;
    this.BookInfoList = BookInfoList;
    //this.itemLayout = itemLayout;
}



@Override
public void onBindViewHolder(final ViewHolder viewHolder, final int position) {


viewHolder.ITEM_BOOKNAME.setText(BookInfoList.get(position).getBook_name());
viewHolder.ITEM_AUTHOR.setText(BookInfoList.get(position).getAuthor());
viewHolder.ITEM_TAG.setText(BookInfoList.get(position).getTags());


// 값 설정 ( set )
//Here it is simply write onItemClick listener here
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Context context = v.getContext();

//like, read버튼 클릭시 이벤트 처리 here


Intent intent = new Intent(v.getContext(),BookDetailActivity.class);

intent.putExtra("isbn",BookInfoList.get(position).getIsbn());
intent.putExtra("book_thumbnail",BookInfoList.get(position).getThumbnail());
intent.putExtra("book_name",BookInfoList.get(position).getBook_name());
intent.putExtra("book_author",BookInfoList.get(position).getAuthor());
intent.putExtra("book_content",BookInfoList.get(position).getContents());
intent.putExtra("book_country",BookInfoList.get(position).getCountry());
intent.putExtra("book_tags",BookInfoList.get(position).getTags());

mContext.startActivity(intent);

Toast.makeText(context, position +"번째 아이템 클릭", Toast.LENGTH_LONG).show();
}
});

    } 



그리고 이 adapter 만든 액티비티에서는

adapter = new RecyclerViewAdapter(getApplicationContext(), books);

이렇게 호출해줬음.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 
 
 
 

'Develop > Android' 카테고리의 다른 글

[Android] 시작화면 바꾸기 LAUNCHER  (0) 2019.02.07
editText focus 없애기  (0) 2019.01.26
[Android] ImageView에 url 지정  (0) 2019.01.25
[Android] FlowLayout  (0) 2019.01.19
[Android/Git] GitKraken 이용법 - commit/push/merge/branch  (0) 2019.01.19
출처: https://mingos-habitat.tistory.com/34 [밍고의서식지:티스토리]