Posts

Showing posts from January, 2020

CheckBox | Android Studio | Kotlin

Image
CheckBox | Android Studio | Kotlin CheckBoxes are used to select one or more options from the available options. For example , you have a list of colors and the user can choose one or more colors from that list. We can use the CheckBox widget of android in such scenarios. >>Watch For Java Step 1:  Create a new project   or   open an existing project Step 2: Code Check If CheckBox is checked or not if (androidCb.isChecked) { //check box is checked } else { //check box is not checked or unchecked } Add  CheckedChange Listener on a CheckBox androidCb.setOnCheckedChangeListener { _, isChecked -> //check if checkbox is checked or not if (isChecked) { //checkbox is checked } else { //checkbox is not checked } } Complete Example activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:androi...

CheckBox | Android Studio | Java

Image
CheckBox | Android Studio | Java CheckBoxes are used to select one or more options from the available options. For example , you have a list of colors and the user can choose one or more colors from that list. We can use the CheckBox widget of android in such scenarios. >>Watch For Kotlin Step 1:  Create a new project   OR   Open your existing project Step 2:  Code Check If CheckBox is checked or not if ( androidCb . isChecked ()) { //check box is checked } else { //check box is not checked or unchecked } Add CheckedChange Listener on a CheckBox androidCb . setOnCheckedChangeListener ( new CompoundButton . OnCheckedChangeListener () { @Override public void onCheckedChanged ( CompoundButton buttonView , boolean isChecked ) { //check if checkbox is checked or not if ( isChecked ) { //checkbox is checked } e...

SharedPreferences - Android Studio - Java

Image
How to use SharedPreferences using Android Studio with Java SharedPreferences in Android Studio is one of the simplest and most commonly used ways to store small amounts of data on Android devices. It allows you to save values in the form of key–value pairs , making it ideal for storing lightweight and persistent data such as user settings, app preferences, login states, theme choices, and more. SharedPreferences supports saving the following data types: String, int, boolean, long, float, and Set<String> . Because it is lightweight and fast, it is recommended when you need to store a small collection of simple key-value data. Using SharedPreferences, you can easily add , update , and remove stored values without needing complex storage solutions like databases. To access SharedPreferences in Android, you can use any of the following APIs depending on your requirement: getPreferences() – Accesses preferences that belong to a single Activity. Useful when the data is spe...

SharedPreferences - Android Studio - Kotlin

Image
How to use SharedPreferences using Android Studio with Kotlin SharedPreferences in Android Studio is one of the simplest and most commonly used ways to store small amounts of data on Android devices.  It allows you to save values in the form of  key–value pairs , making it ideal for storing lightweight and persistent data such as user settings, app preferences, login states, theme choices, and more. SharedPreferences supports saving the following data types:  String, int, boolean, long, float, and Set<String> . Because it is lightweight and fast, it is recommended when you need to store a small collection of simple key-value data. Using SharedPreferences, you can easily  add ,  update , and  remove  stored values without needing complex storage solutions like databases. To access SharedPreferences in Android, you can use any of the following APIs depending on your requirement: getPreferences()  – Accesses preferences that belong to a single...