How to pass data from RecyclerView of fragment to another fragment.i getting error. when I start the app, the app crash within 5 seconds with the message
My RecyclerView of fragment..
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
final Categories categories = categoriesList.get(position);
holder.name.setText((categories.getName()));
Glide.with(context).load(categories.getThumbnail()).into(holder.thumbnail);
holder.name.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String catId= String.valueOf(categories.getId());
Toast.makeText(context,catId,Toast.LENGTH_SHORT).show();
AppCompatActivity activity = (AppCompatActivity) view.getContext();
AudioFragment myFragment = new AudioFragment();
Bundle bundle=new Bundle();
bundle.putString("name", catId); //key and value
myFragment.setArguments(bundle);
activity.getSupportFragmentManager().beginTransaction().replace(R.id.frag_container, myFragment).addToBackStack(null).commit();
}
});
}
New Fragment
public class AudioFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
String CAT_ID = getArguments().getString("name");
Toast.makeText(getContext(),CAT_ID,Toast.LENGTH_SHORT).show();
return inflater.inflate(R.layout.fragment_audio, container, false);
}
}