Created
June 25, 2021 11:24
-
-
Save extsalt/7786169a4442969825f96409e4823d18 to your computer and use it in GitHub Desktop.
Android Checkbox demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.mycalculator; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.widget.Button; | |
import android.widget.CheckBox; | |
import android.widget.CompoundButton; | |
import android.widget.Toast; | |
public class MainActivity extends AppCompatActivity { | |
Button button; | |
CheckBox math, phy; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
math = this.findViewById(R.id.math); | |
math.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |
@Override | |
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |
String message = ""; | |
if (isChecked) { | |
message = "You selected "; | |
} else { | |
message = "You did not select"; | |
} | |
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show(); | |
} | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment