LoginSignup
13
10

More than 5 years have passed since last update.

Android DialogFragmentで引数を扱う

Last updated at Posted at 2016-09-27

ダイアログを呼び出す側で、引数を渡すところ

HogeFragment.java
// 〜省略
dialogFragment = new AlertDialogFragment();
Bundle args = new Bundle();
args.putInt("hoge_arg1",position); //引数
dialogFragment.setArguments(args);
dialogFragment.show(getActivity().getFragmentManager(),"dialog");
// 〜省略

ダイアログ表示に渡しした引数を取得するところ

AlertDialogFragment.java
// 〜省略
// アラートダイアログ
public static class AlertDialogFragment extends DialogFragment {

    private AlertDialog.Builder alert;

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        alert = new AlertDialog.Builder(getActivity());
        int hogeInt = getArguments().getInt("hoge_arg1");
// 〜省略
13
10
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
10