set onclick listener not working in android for moving from one fragment to another activity [duplicate]

I will suggest to Override onActivityCreated method :

 public View onCreateView(LayoutInflater inflater, ViewGroup container,
   Bundle savedInstanceState) {

   View view = inflater.inflate(R.layout.fragment_home, container, false);
  return view;

  public void onActivityCreated(Bundle savedInstanceState) {
     images = (ImageView) view.findViewById(;
     images.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
    Intent intent=new Intent(getActivity(), DetailPost.class);

I will suggest to try to change your code. It will work

Browse More Popular Posts

Leave a Comment