Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

doesn't show getSupportFragmentManager on ViewHolder in RecyclerView

In ViewHolder, I can't call getSupportFragmentManager.

I want to change between Fragment

I searched all of the google page. but I can't find it.

public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{

    public ImageView imgThumbnail;//img
    public TextView tvspecies; //text

    public ViewHolder(View itemView) {
        super(itemView);

        imgThumbnail = (ImageView)itemView.findViewById(R.id.img_thumbnail);
        tvspecies = (TextView)itemView.findViewById(R.id.tv_species);

        itemView.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {/*버튼 실행했을때 실행부분*/

        Fragment fm=new NewsFragment();
        FragmentTransaction transaction=fm.getFragmentManager().beginTransaction();
        transaction.replace(R.id.Linearcontainer, fm);
        transaction.addToBackStack(null);
        transaction.commit();

    }//onClick


}//ViewHolder
like image 299
Daehan Bang Avatar asked Aug 25 '15 12:08

Daehan Bang


1 Answers

Try this one

public HorizontalProductAdapter(Activity context, List<RecycleIndividualProduct>data, FragmentManager fragmentManager){
        inflater = LayoutInflater.from(context);
        this.subActivityData = data;
        this.fragmentManager=fragmentManager;
}

and call your adapter from your activity or fragment

 mAdapter = new HorizontalProductAdapter(getActivity(),allDeals,getFragmentManager());
like image 145
Swapnil Kshirsagar Avatar answered Nov 13 '22 00:11

Swapnil Kshirsagar