-3

I have a viewPager with some fragments (in a fragment I have a recyclerView ), recyclerView contains more items, so, I want to when I click a item on recyclerView,it trans to BBBBActivity. But I don't figure out.

enter image description here

it errors thank you very much

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Danh
  • 11
  • 1
  • 1
  • 4

3 Answers3

1

You need a context to call startActivity(). Pass getActivity() as a context from your Fragment where you are initializing your adapter; like:

YourAdapter adapter = new YourAdapter(getActivity, /* other parameters*/);

In adapter:

private Context mContext;

YourAdapter(Context context, /*other parameters*/) {
    mContext = context;
}

And then use mContext to call startActivity():

mContext.startActivity();
Shruti
  • 803
  • 9
  • 26
1

try this

Intent intent= new Intent(itemView.getContext(),addsongList.class);
itemView.getContext().startActivity(intent);
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
1

change your code like this or pass the Context in your adapter

Intent intent= new Intent(itemView.getContext(),AddSongToList.class);
getActivity.startActivity(intent);
HassanUsman
  • 1,787
  • 1
  • 20
  • 38