0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Android ToggleButtonの状態変更

Last updated at Posted at 2017-05-03

1.トグルボタンの状態をプログラムで変更する場合の注意点

プログラムから意図的にトグルボタンの状態を変更する時setTexOn("ON")や
setTexOFF("OFF")だけやっても状態は変わりません。
必ず最後に

 tb1.setChecked(true);
 tb1.setChecked(false);
もやる必要あり。

image.png
これでプログラムを実行すると。
image.png
このようにONNNという記載になってくれません。。

しかし、setChecked()を実行してやれば。
image.png

image.png
こんな感じに言うことを聞いてくれます。ここで補足ですが、setCheckedはボタン押下のリスナーではやらなくても大丈夫です。

ボタンの状態1つ変更するにもAndroidは大変なのであります。
<(`・ω・´)

いじょ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?