I have a Relative layout and an ok button in mainActivity. On ok button click, a fragment will be added to this Relative layout. This Fragment has a cancel button.I want it to close that fragment on cancel button click.
public class filter_Fragment extends Fragment {
Button cancel;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View rootView=inflater.inflate(R.layout.fragment_filter_,container, false);
cancel=(Button)rootView.findViewById(R.id.cancel);
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
//Close fragment page. Return to mainActivity
}
});
return rootView;
}