-3

I am implementing navigation drawer, I need to handle an onClick method from a fragment, how can I achieve this?. In Mainactivity.java this can be performed easily but when I use fragments it's not possible to use findViewbyid?

Thank You

Julian Schmuckli
  • 3,393
  • 11
  • 33
  • 59

1 Answers1

2

In fragment, you can simply use View to handle buttons in Fragment.

View view = inflater.inflate(R.layout.yourFragment, container, false);
myButton = (Button) view.findViewById(R.id.myButton);
myButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        //Some code...
    }
});
return view;
Vishal Yadav
  • 3,552
  • 3
  • 23
  • 41
Cagri Yalcin
  • 392
  • 4
  • 13