2017-02-17 19 views
0

別のボタン(Btn2)をクリックすると状態が「未チェック」に変更される画像ボタン(Btn1)を作成しようとしています。私はすでにブール値でそれをやろうとしましたが、ブール値が変更されたときにボタンの状態は変化しませんでした。私は "setChecked"メソッドについて聞いたことがありますが、どのように使用するかを見つけることができませんでした...ボタンを他のボタンでチェックする/チェックを解除する方法は?

お返事ありがとうございます。

imageButton_info = (ImageButton)findViewById(R.id.imageButton_info); 
    imageButton_info.setOnClickListener(new View.OnClickListener(){ 
     @Override 
     public void onClick(View v){... 
+0

[setChecked(真/偽)](https://developer.android.com/reference/android/widget/CompoundButton.html# setChecked%28ブール値%29) – Blakethepatton

答えて

0

RadioButtonの代わりImageButtonを使用しないのはなぜ。あなたは、バックグラウンドは、それがチェックされているかどうかに依存して表示するために、独自のセレクターを設計することができます。それが役に立てば幸い。

0

ImageButtonには、setChecked(...)メソッドがありません。それはRadioButtonが、この場合に最適です、あなたはとにかくこの

final ToggleButton button1 = (ToggleButton) findViewById(R.id.button1); 
final ToggleButton button2 = (ToggleButton) findViewById(R.id.button2); 

button1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
     @Override 
     public void onCheckedChanged(CompoundButton compoundButton, boolean b) { 
       button2.setChecked(!b); 
     } 
}); 
button2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
     @Override 
     public void onCheckedChanged(CompoundButton compoundButton, boolean b) { 
      button1.setChecked(!b); 
     } 
}); 

ようToggleButtonを使用することができますToggleButtonの方法です。

0

ImageButtonの代わりに次のものを使用できます。

  • ラジオボタン
  • スイッチ
  • チェックボックス
関連する問題