0

私のメイン アクティビティには、グループ ラジオ ボタンがあります。それぞれがクリックされると、異なるアクティビティが開始されます。すべてのアクティビティの XML は同じですが、入力と機能は異なります。つまり、ラジオ グループはすべてのアクティビティに共通です。例: 最初のラジオ ボタンをクリックすると、別のアクティビティが開始され、ラジオ ボックスの選択が消えます。別のアクティビティであっても、グループの別のラジオ ボタンがクリックされるまで、クリックされたラジオ ボタンの選択をオンにしておく必要があります。これを機能させるにはどうすればよいですか?どんな助けでも大歓迎です!

public void onRadioButtonClicked(View view){
     boolean checked = ((RadioButton) view).isChecked();

    // Check which radio button was clicked
    switch(view.getId()) {
        case R.id.radio_199os:
            if (checked){

                Intent intent = new Intent(MainActivity.this, second.class);
                startActivity(intent);


            }

            break;
        case R.id.radio_399os:
            if (checked){
                Intent intent = new Intent(MainActivity.this, Third.class);
                startActivity(intent);
            }                 

            break;
        case R.id.radio_2000os:
            if (checked){
                Intent intent = new Intent(MainActivity.this, Fourth.class);
                startActivity(intent);
            }
                //
            break;
    }         

}
4

1 に答える 1

1

選択したチェックチェックを行うには、以下を追加する必要があります

radio_2000os.setChecked(true);

他の人のチェックを外します

radio_199os.setChecked(false);

あなたのコードはこのようになります

  public void onRadioButtonClicked(View view){
     boolean checked = ((RadioButton) view).isChecked();

    // Check which radio button was clicked
    switch(view.getId()) {
        case R.id.radio_199os:
            if (checked){

                Intent intent = new Intent(MainActivity.this, second.class);
                startActivity(intent);
                 radio_2000os.setChecked(false);
                 radio_399os.setChecked(false);
                 radio_199os.setChecked(true);


            }

            break;
        case R.id.radio_399os:
            if (checked){
                Intent intent = new Intent(MainActivity.this, Third.class);
                startActivity(intent);
                 radio_2000os.setChecked(false);
                 radio_399os.setChecked(true);
                 radio_199os.setChecked(false);
            }                 

            break;
        case R.id.radio_2000os:
            if (checked){
                Intent intent = new Intent(MainActivity.this, Fourth.class);
                startActivity(intent);
                 radio_2000os.setChecked(true);
                 radio_399os.setChecked(false);
                 radio_199os.setChecked(false);
            }
                //
            break;
    }         

}
于 2013-01-29T07:19:03.000 に答える