Android Studio AlertDialog Pass Values to DialogFragment 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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