Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created January 30, 2021 07:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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);
}
public void showDialog(View view) {
// DialogFragmentの用意
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