-2

I have this piece of code in a fragment but it says cannot resolve method findViewById

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

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

        }
    });
}
En Xin
  • 929
  • 1
  • 6
  • 9

1 Answers1

4

It should be:

FloatingActionButton fab = (FloatingActionButton)fragmentLayout.findViewById(R.id.fab);
xxx
  • 3,315
  • 5
  • 21
  • 40