getSupportFragmentManager

getSupportFragmentManager

本文介绍了在RecyclerView的ViewHolder上不显示getSupportFragmentManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ViewHolder中,我无法呼叫getSupportFragmentManager.

我想在片段之间切换

我搜索了所有的google页面.但我找不到它.

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

推荐答案

尝试这个

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());

这篇关于在RecyclerView的ViewHolder上不显示getSupportFragmentManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 15:31