2

それぞれが3つのRadioButtonで構成される3つのRadioGroupのセットがあります。また、すべてのグループのすべてのラジオボタンをfalseに設定するリセットボタン(setChecked(false))。

リセットは正常に機能します(すべてのラジオボタンがオフになっています)。ただし、リセット後、各RadioGroupで、リセットボタンがクリックされた時点でチェックされていない2つのボタンのみをチェックできます。その後、グループ内の3つのボタンすべてを以前と同じように再度チェックできます。

リセット中にsetFocusable(true)とsetClickable(true)を追加しようとしましたが、違いはありません。それでは、他に何がフォーカスまたはクリック可能性によってこれを引き起こし、どのように解決するのでしょうか?

AndroidAPI7をターゲットにしています。

完全なMainActivity.javaは次のとおりです。

    package nl.ch.simplescore;

import nl.ch.simplescore.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;

public class MainActivity extends Activity {

    Button scoretoevoegenButton; 
    RadioButton radio11RadioButton;
    RadioButton radio12RadioButton;
    RadioButton radio13RadioButton;
    RadioButton radio21RadioButton;
    RadioButton radio22RadioButton;
    RadioButton radio23RadioButton;
    RadioButton radio31RadioButton;
    RadioButton radio32RadioButton;
    RadioButton radio33RadioButton;

    TextView textView15;
    TextView textView16;
    TextView textView17;
    TextView textView18;
    TextView textView19;
    TextView textView20;
    TextView textView21;
    TextView textView22;
    TextView textView23;
    TextView textView24;
    TextView textView25;
    TextView textView26;


    int speler1score = 0;
    int speler2score = 0;
    int speler3score = 0;

    int speler1score123 = 0;
    int speler1score12 = 0;
    int speler1score13 = 0;
    int speler1score23 = 0;
    int speler2score123 = 0;
    int speler2score12 = 0;
    int speler2score13 = 0;
    int speler2score23 = 0;
    int speler3score123 = 0;
    int speler3score12 = 0;
    int speler3score13 = 0;
    int speler3score23 = 0;

    int speler1sumscore123 = 0;
    int speler1sumscore12 = 0;
    int speler1sumscore13 = 0;
    int speler1sumscore23 = 0;
    int speler2sumscore123 = 0;
    int speler2sumscore12 = 0;
    int speler2sumscore13 = 0;
    int speler2sumscore23 = 0;
    int speler3sumscore123 = 0;
    int speler3sumscore12 = 0;
    int speler3sumscore13 = 0;
    int speler3sumscore23 = 0;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        scoretoevoegenButton = (Button) this.findViewById(R.id.button1);
        radio11RadioButton = (RadioButton) this.findViewById(R.id.radio11);
        radio12RadioButton = (RadioButton) this.findViewById(R.id.radio12);
        radio13RadioButton = (RadioButton) this.findViewById(R.id.radio13);
        radio21RadioButton = (RadioButton) this.findViewById(R.id.radio21);
        radio22RadioButton = (RadioButton) this.findViewById(R.id.radio22);
        radio23RadioButton = (RadioButton) this.findViewById(R.id.radio23);
        radio31RadioButton = (RadioButton) this.findViewById(R.id.radio31);
        radio32RadioButton = (RadioButton) this.findViewById(R.id.radio32);
        radio33RadioButton = (RadioButton) this.findViewById(R.id.radio33);

        textView15 = (TextView) this.findViewById(R.id.textView15);
        textView16 = (TextView) this.findViewById(R.id.textView16);
        textView17 = (TextView) this.findViewById(R.id.textView17);
        textView18 = (TextView) this.findViewById(R.id.textView18);
        textView19 = (TextView) this.findViewById(R.id.textView19);
        textView20 = (TextView) this.findViewById(R.id.textView20);
        textView21 = (TextView) this.findViewById(R.id.textView21);
        textView22 = (TextView) this.findViewById(R.id.textView22);
        textView23 = (TextView) this.findViewById(R.id.textView23);
        textView24 = (TextView) this.findViewById(R.id.textView24);
        textView25 = (TextView) this.findViewById(R.id.textView25);
        textView26 = (TextView) this.findViewById(R.id.textView26);

            }

    public void radio11ClickHandler(View v) {
        speler1score = 3;
    }

    public void radio12ClickHandler(View v) {
        speler1score = 2;
    }

    public void radio13ClickHandler(View v) {
        speler1score = 1;
    }

    public void radio21ClickHandler(View v) {
        speler2score = 3;
    }

    public void radio22ClickHandler(View v) {
        speler2score = 2;
    }

    public void radio23ClickHandler(View v) {
        speler2score = 1;
    }

    public void radio31ClickHandler(View v) {
        speler3score = 3;
    }

    public void radio32ClickHandler(View v) {
        speler3score = 2;
    }

    public void radio33ClickHandler(View v) {
        speler3score = 1;
    }

    public void scoretoevoegenClickHandler(View v) {
        scoreTonen();
    }

    public void resetClickHandler(View v) {
        speler1score = 0;
        speler2score = 0;
        speler3score = 0;

        radio11RadioButton.setChecked(false);
        radio12RadioButton.setChecked(false);
        radio13RadioButton.setChecked(false);
        radio21RadioButton.setChecked(false);
        radio22RadioButton.setChecked(false);
        radio23RadioButton.setChecked(false);
        radio31RadioButton.setChecked(false);
        radio32RadioButton.setChecked(false);
        radio33RadioButton.setChecked(false);

        textView15.setText(null);
        textView16.setText(null);
        textView17.setText(null);
        textView18.setText(null);
        textView19.setText(null);
        textView20.setText(null);
        textView21.setText(null);
        textView22.setText(null);
        textView23.setText(null);
        textView24.setText(null);
        textView25.setText(null);
        textView26.setText(null);

    }

    public void scoreTonen() {
        int kolom; 

        kolom = 0;
        if (speler1score!=0) {
            if (speler2score!=0 && speler3score!=0) {
                kolom = 123;
            }
            if (speler2score!=0 && speler3score==0) {
                kolom = 12;
            }
            if (speler2score==0 && speler3score!=0) {
                kolom = 13;
            }
            switch (kolom) {
            case 123: 
                textView15.setText(Integer.toString(speler1score));
                break;
            case 12:    
                textView16.setText(Integer.toString(speler1score));
                break;
            case 13:
                textView17.setText(Integer.toString(speler1score));
                break;
            default: // niets doen  
            }
        }

        kolom = 0;
        if (speler2score!=0) {
            if (speler1score!=0 && speler3score!=0) {
                kolom = 123;
            }
            if (speler1score!=0 && speler3score==0) {
                kolom = 12;
            }
            if (speler1score==0 && speler3score!=0) {
                kolom = 23;
            }
            switch (kolom) {
            case 123: 
                textView19.setText(Integer.toString(speler2score));
                break;
            case 12:    
                textView20.setText(Integer.toString(speler2score));
                break;
            case 23:
                textView22.setText(Integer.toString(speler2score));
                break;
            default: // niets doen  
            }
        }

        kolom = 0;
        if (speler3score!=0) {
            if (speler1score!=0 && speler2score!=0) {
                kolom = 123;
            }
            if (speler1score!=0 && speler2score==0) {
                kolom = 13;
            }
            if (speler1score==0 && speler2score!=0) {
                kolom = 23;
            }
            switch (kolom) {
            case 123: 
                textView23.setText(Integer.toString(speler3score));
                break;
            case 13:    
                textView25.setText(Integer.toString(speler3score));
                break;
            case 23:
                textView26.setText(Integer.toString(speler3score));
                break;
            default: // niets doen  
            }
        }
    }

    public void sumScoreTonen() {
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}
4

2 に答える 2

11

ここで見つけました:

チェックの問題をクリアした後のandroidラジオボタンチェック

個別のボタンごとに、radioButton.setChecked(false)の代わりにradioGroup.clearCheck()を使用する必要があります。

于 2012-11-24T15:55:27.087 に答える
0

RadioButtonグループはこのルールを適用します。常に1つのオプションのみが選択されます。すべてのチェックを外したり、複数のチェックを外したりしないでください。CheckBoxそのような使用のために設計されています。

于 2012-11-24T14:08:32.207 に答える