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
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
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;