Easy Tutorial
❮ Python Locals Globals Remainder And The Modulo ❯

2.3.5. RadioButton (Single-choice Button) & Checkbox (Multiple-choice Box)

Category Android Basic Tutorial

Introduction:

>

This section introduces the basic UI components in Android: RadioButton and Checkbox. First, we will cover the 1. Basic Usage of RadioButton and Checkbox.

These two components are similar in many aspects, except for single-choice and multiple-choice, event handling, and other similar features! Additionally, there is an issue with Checkbox misalignment on ListView, which we will address in the ListView chapter. Now, let's get started with this section. Official documentation API: RadioButton; CheckBox;


1. Basic Usage and Event Handling:


1) RadioButton (Single-choice Button)

>

As the name suggests, a single-choice button allows only one selection, so we need to place RadioButton in a RadioGroup to achieve this functionality. Let's familiarize ourselves with how to use RadioButton with a simple example of gender selection: We can also set the orientation attribute for the outer RadioGroup and arrange the RadioButtons vertically or horizontally.

Effect Diagram:

if(cb_one.isChecked()) choose += cb_one.getText().toString() + "";
if(cb_two.isChecked()) choose += cb_two.getText().toString() + "";
if(cb_three.isChecked()) choose += cb_three.getText().toString() + "";
Toast.makeText(this, choose, Toast.LENGTH_SHORT).show();
}
}

2. Custom Click Effects

>

Although RadioButton and Checkbox have improved slightly since version 5.0, they may still not meet our preferences or requirements. We might need custom click effects! Implementing this is straightforward. First, create a custom selector resource to set the toggle images for checked and unchecked states.

Here is the effect diagram: -2.6.1 Basic Usage of PopupWindow (Floating Box)

-2.6.2 Menu (Menu)

-2.6.3 Simple Usage of ViewPager

-2.6.4 Simple Usage of DrawerLayout (Official Side Sliding Menu)

-3.1.1 Event Handling Mechanism Based on Listeners

-3.2 Event Handling Mechanism Based on Callbacks

-3.3 Analysis of Handler Message Passing Mechanism

-3.4 TouchListener PK OnTouchEvent + Multi-touch

-3.5 Listening for Content Changes in EditText

-3.6 Responding to System Setting Events (Configuration Class)

-3.7 AsyncTask Asynchronous Task

-3.8 Gestures (Gestures)

-4.1.1 Activity Beginner's Guide

-4.1.2 Activity Intermediate Guide

-4.1.3 Activity Advanced Guide

-4.2.1 Service Introduction

-4.2.2 Service Advanced

-4.2.3 Service Mastery

-4.3.1 BroadcastReceiver Beginner's Guide

-4.3.2 BroadcastReceiver Advanced Guide

-4.4.1 ContentProvider Introduction

-4.4.2 ContentProvider Deep Dive - Document Provider

-4.5.1 Basic Usage of Intent

-4.5.2 Passing Complex Data with Intent

-5.1 Fragment Basic Overview

-5.2.1 Fragment Example Analysis - Bottom Navigation Bar Implementation (Method 1)

-5.2.2 Fragment Example Analysis - Bottom Navigation Bar Implementation (Method 2)

-5.2.3 Fragment Example Analysis - Bottom Navigation Bar Implementation (Method 3)

-5.2.4 Fragment Example Analysis - Bottom Navigation Bar + ViewPager Swipe to Switch Pages

-5.2.5 Fragment Example Analysis - Simple Implementation of News (Shopping) App List Fragment

-6.1 Data Storage and Access - File Storage and Reading

-6.2 Data Storage and Access - SharedPreferences for Saving User Preferences

-6.3.1 Data Storage and Access - Introduction to SQLite Database

-6.3.2 Data Storage and Access - Dive into SQLite Database

-7.1.1 Android Network Programming Overview and HTTP Protocol Study

-7.1.2 Android HTTP Request and Response Headers Study

-7.1.3 Android HTTP Request Method: HttpURLConnection

-7.1.4 Android HTTP Request Method: HttpClient

-7.2.1 Android XML Data Parsing

-7.2.2 Android JSON Data Parsing

-7.3.1 Android File Upload

-7.3.2 Android File Download (1)

-7.3.3 Android File Download (2)

-7.4 Android Calling WebService

-7.5.1 Basic Usage of WebView (Web View)

-7.5.2 WebView and JavaScript Interaction Basics

-7.5.3 WebView Considerations After Android 4.4

-7.5.4 WebView File Download

-7.5.5 WebView Cache Issues

-7.5.6 WebView Handling Webpage Error Codes

-7.6.1 Socket Network Basics Preparation

-7.6.2 TCP Protocol Based Socket Communication (1)

-7.6.3 TCP Protocol Based Socket Communication (2)

-7.6.4 UDP Protocol Based Socket Communication

-8.1.1 13 Drawable Types in Android Summary Part 1

-8.1.2 13 Drawable Types in Android Summary Part 2

-8.1.3 13 Drawable Types in Android Summary Part 3

-8.2.1 Bitmap (Bitmap) Comprehensive Analysis Part 1

-8.2.2 Bitmap OOM Issues

-8.3.1 Detailed Explanation of Three Drawing Tool Classes

-8.3.2 Drawing Class Practical Examples

-8.3.3 Paint API - MaskFilter (Mask)

-8.3.4 Paint API - Xfermode and PorterDuff Detailed Explanation (Part 1)

-8.3.5 Paint API - Xfermode and PorterDuff Detailed Explanation (Part 2)

-8.3.6 Paint API - Xfermode and PorterDuff Detailed Explanation (Part 3)

-8.3.7 Paint API - Xfermode and PorterDuff Detailed Explanation (Part 4)

-8.3.8 Paint API - Xfermode and PorterDuff Detailed Explanation (Part 5)

-8.3.9 Paint API - ColorFilter (Color Filter) (1/3)

-8.3.10 Paint API - ColorFilter (Color Filter) (2/3)

-8.3.11 Paint API - ColorFilter (Color Filter) (3/3)

-8.3.12 Paint API - PathEffect (Path Effect)

-8.3.13 Paint API - Shader (Image Rendering)

-8.3.14 Paint Enum/Constant Values and ShadowLayer Shadow Effect

-8.3.15 Paint API - Typeface (Font Style)

Follow on WeChat

❮ Python Locals Globals Remainder And The Modulo ❯