0

I have a floating action buttom in a fragment, and I want when it is clicked open an Internet page but not how to do it. I hope you can help me and n ose if it affects the fab is in a fragment thanks

Zoe
  • 27,060
  • 21
  • 118
  • 148
Vicente NT
  • 21
  • 4

1 Answers1

0

It's so simple. This answer can solve your problem. You just need to find your view (in this case a float action button) and set a clickListener for it.

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.your_fragment_layout, container, false);

        fabButton = rootView.findViewById(R.id.fab_button);
        fabButton.setOnClickListener(new View.OnClickListener(){

                @Override
                public void onClick(View v) {
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
                    startActivity(browserIntent);
                }
            });

        return rootView;
    }
Mohammad
  • 792
  • 1
  • 7
  • 15