I am have Fragment on the Activity. Fragment has button. if i click on the button, Fragment must be close. How i am did this?
public class ItemFragment extends Fragment{
private ImageView btnApply;
private ClickButton clickButton = new ClickButton();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.item_info, container, false);
btnApply = (ImageView) rootView.findViewById(R.id.btnSendItem);
btnApply.setOnClickListener(clickButton);
return rootView;
}
private class ClickButton implements View.OnClickListener {
@Override
public void onClick(View v) {
if (R.id.btnSendItem == v.getId()) {
Toast.makeText(getActivity(),"CLOSE",Toast.LENGTH_LONG).show();
return;
}
}
}
}
There's no such thing like close the fragment, but you can remove the fragment from the stack. To pop the fragment use the following inside button click listener
getActivity().getFragmentManager().beginTransaction().remove(this).commit();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With