Toastクラスを利用してRadioButtonの内容を表示させる
トーストとは?
トーストとは、Androidアプリで画 に短いメッセージを表示するための機能
- String しか表示できない
- 一定時間が経過すると、 フェードアウトする
あの、下にふわって出てくるやつ。
public static Toast makeText(Context context, CharSequence text, int duration)
context:コンテキスト text:トーストに表示する文字列 duration:表示時間
// Toastオブジェクトの生成 Toast toast = Toast.makeText(this, R.string.message, Toast.LENGTH_LONG); // Toastの表示 Toast.show();
実装
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radio_group); RadioButton radioButton = (RadioButton) findViewById(radioGroup.getCheckedRadioButtonId()); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { RadioButton checkedButton = (RadioButton) findViewById(checkedId); Log.d("MainActivity", checkedButton.getText().toString()); Toast.makeText(MainActivity.this, checkedButton.getText().toString(), Toast.LENGTH_LONG).show(); } });