I have created a bottom fragment and now i need some data from bottom fragment in the main activity when a button is clicked in bottom fragment. I saw few answers by creating interface but not very clear with the concept.
Code:
Main activity using this function to call fragment:
public void showSchedule() {
BottomSheetFrag bottomSheetFragment = new BottomSheetFrag();
Bundle bundle = new Bundle();
bundle.putString("UserId", Parlour_BeauticianID);
bottomSheetFragment.setArguments(bundle);
bottomSheetFragment.show(getSupportFragmentManager(), bottomSheetFragment.getTag());
}
Fragment:
public class BottomSheetFrag extends BottomSheetDialogFragment {
public static BottomSheetFrag newInstance() {
return new BottomSheetFrag();
}
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.activity_appointment, container, false);
Bundle bundle = getArguments();
userID = bundle.getString("UserId");
ImageView imageViewClose = (ImageView) view.findViewById(R.id.imageClose);
final Fragment f = getActivity().getFragmentManager().findFragmentById(R.id.Linear_layout);
imageViewClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
button9AM1 = (Button) view.findViewById(R.id.button9AM1);
/* when i click the button9AM1 i want to send the data as as 9AM to main activity */
}}