Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created December 19, 2023 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeforfun-jp/688111e2d97fdc43bc6de0544c6adb19 to your computer and use it in GitHub Desktop.
Save codeforfun-jp/688111e2d97fdc43bc6de0544c6adb19 to your computer and use it in GitHub Desktop.
Android Studio AlertDialog Pass Values to DialogFragment 1
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn).setOnClickListener(view -> {
DialogFragment dialogFragment = new MyDialogFragment();
// 値を渡す
Bundle args = new Bundle();
args.putString("TITLE", "こんにちは");
args.putInt("NUMBER", 123);
dialogFragment.setArguments(args);
dialogFragment.show(getSupportFragmentManager(), "my_dialog");
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment