Dynamically Create View Elements - Android Example
Get Registered Email Accounts - Android Example
Create Notification Alert - Android Example
Skew Or Bind Image On SDCARD - Android Example
Swipe screen left right top bottom
Create Repeating Alarm Start After Each 2 Minutes
In this example creating a date picker to pick day month year of date.
Time Picker With AM_PM Values - Android Example
In This example creating checkbox and listener to listen checkbox click and show selected checkbox value.
Checkboxes allow the user to select one or more options from a set.
Create a CheckBox in your layout. Checkbox options allows the user to select multiple items, each checkbox is managed separately and you must register a click listener for each one.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <CheckBox android:id="@+id/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Android" /> <CheckBox android:id="@+id/java" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Java" android:checked="true" /> <CheckBox android:id="@+id/opencv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="OpenCV" /> <Button android:id="@+id/Clickhere" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Click here" /> </LinearLayout>
import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.CheckBox; import android.widget.Toast; public class CheckboxExample extends Activity { private CheckBox android, java, opencv; private Button Clickhere; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); android = (CheckBox) findViewById(R.id.android); java = (CheckBox) findViewById(R.id.java); opencv = (CheckBox) findViewById(R.id.opencv); Clickhere = (Button) findViewById(R.id.Clickhere); Clickhere.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Create string buffer to StringBuffer OUTPUT = new StringBuffer(); OUTPUT.append("Android : ") .append(android.isChecked()); OUTPUT.append("\nJava : ").append( java.isChecked()); OUTPUT.append("\nOpenCV :").append( opencv.isChecked()); Toast.makeText(CheckboxExample.this, OUTPUT.toString(), Toast.LENGTH_LONG).show(); } }); } }
Final words- Just download the project and run it using your emulator and if you have any doubts or suggestions, please place them in the comments.