Pass Data From Activity To Dialog

后端 未结 4 1250
一整个雨季
一整个雨季 2021-01-17 21:31

I am looking for a way to pass data from an activity onto a dialog box. I am trying to call showDialog(int);, however i don\'t see a way to pass any data to the

4条回答
  •  耶瑟儿~
    2021-01-17 22:00

    I know this question is old, but you can use the setArguments method if you are using a custom dialog.

    String myString = "How to do it"
    DialogFragment newFragment = new AddUserDialog();
                    Bundle args = new Bundle();
                    args.putString("number", myString); //The first parameter is the key that will be used to retrieve the value, which is the second parameter.
                    newFragment.setArguments(args);
                    newFragment.show(getSupportFragmentManager(), "add_a_member");
    

提交回复
热议问题