3
5

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.

【Kotlin/Android】Listenerのかきかえ

Posted at
main.java
 // idがswitchButtonのSwitchを取得
        Switch switchButton = (Switch) findViewById(R.id.switchButton);
        // switchButtonのオンオフが切り替わった時の処理を設定
        switchButton.setOnCheckedChangeListener(
                new CompoundButton.OnCheckedChangeListener(){
                    public void onCheckedChanged(CompoundButton comButton, boolean isChecked){
                        // オンなら
                        if(isChecked){
                        }
                        // オフなら
                        else{
                        }
                    }
                }
        );
    }
main.kt
switch.setOnCheckedChangeListener { _, isChecked ->
            if (isChecked) {
                // ONの処理

            } else {
                // OFFの処理
            }
        }
3
5
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
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?