How to move from one fragment to another fragment on click of an ImageView in Android?

后端 未结 6 1307
不知归路
不知归路 2020-12-03 10:16

I have an ImageView. I want to move from one fragment to another fragment on a click of an Imageview, the same way like we can move from one activity to another using

<
6条回答
  •  半阙折子戏
    2020-12-03 11:23

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_profile, container, false);
        notification = (ImageView)v.findViewById(R.id.notification);
    
        notification.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FragmentTransaction fr = getFragmentManager().beginTransaction();
                fr.replace(R.id.container,new NotificationFragment());
                fr.commit();
            }
        });
    
        return v;
    }
    

提交回复
热议问题