Q:

How to set value to bottom sheet with fragment?

I create a bottom sheet fragment,i can display it, now i want to set value to this fragment. So i try to use Bundle to do that.
But there is no value when i open the bottom sheet fragment.
Here is my bottom sheet fragment layout with TextView:
        <TextView
            android:id="@+id/edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

And here is my bottom sheet fragment:
public class BottomSheetFragment extends Fragment {

    private String TAG = BottomSheetFragment.class.getSimpleName();
    private TextView edit_text;
    private View view;

    public BottomSheetFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_bottom_sheet, container, false);

        edit_text =(TextView) view.findViewById(R.id.edit_text);
        Bundle bundle = getArguments();
        String test = bundle.getString("test");

        Log.d(TAG, "HI"); // there is no HI
        Log.d(TAG, test); // i can't see test value from logcat
        edit_text.setText(test); // so this code is no working

        return view;
    }

}

Here is i try to set value to fragment:
        BottomSheetFragment bottomSheetFragment = new BottomSheetFragment();
        Bundle bundle = new Bundle();
        bundle.putString("test", "oh ya");
        bottomSheetFragment.setArguments(bundle);
        ((MainActivity)getActivity()).showBottomSheetDialog();

Finally here is my showBottomSheetDialog method with MainActivity:
public void showBottomSheetDialog() {
    View view = getLayoutInflater().inflate(R.layout.fragment_bottom_sheet, null);

    BottomSheetDialog dialog = new BottomSheetDialog(this);
    dialog.setContentView(view);
    dialog.show();
}

What step do i miss it ? Any help would be appreciated. Thanks in advance.

A:

If you are willing to use the behavior of BottomSheetDialog, you have to extend BottomSheetDialogFragment to that class.
public class BottomSheetFragment extends BottomSheetDialogFragment {
    ....
    ...
}

And you can directly call show() to that BottomSheetFragment
BottomSheetFragment bottomSheetFragment = new BottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putString("test", "oh ya");
bottomSheetFragment.setArguments(bundle);
bottomSheetFragment.show(getSupportFragmentManager()); // Assuming you are using Activity

