Android Checkbox setOnCheckedChangeListener Example
MainActivity.java
package bipin.rupadiya.checkboxexample;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CheckBox eng = (CheckBox) findViewById(R.id.chkEnglish);
CheckBox hin = (CheckBox) findViewById(R.id.chkHindi);
CheckBox guj = (CheckBox) findViewById(R.id.chkGujarati);
eng.setOnCheckedChangeListener( new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Check box "+arg0.getText().toString()+" is "+String.valueOf(arg1) , Toast.LENGTH_LONG).show();
}
} );
hin.setOnCheckedChangeListener( new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Check box "+arg0.getText().toString()+" is "+String.valueOf(arg1) , Toast.LENGTH_LONG).show();
}
} );
guj.setOnCheckedChangeListener( new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Check box "+arg0.getText().toString()+" is "+String.valueOf(arg1) , Toast.LENGTH_LONG).show();
}
} );
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CheckBox eng = (CheckBox) findViewById(R.id.chkEnglish);
CheckBox hin = (CheckBox) findViewById(R.id.chkHindi);
CheckBox guj = (CheckBox) findViewById(R.id.chkGujarati);
eng.setOnCheckedChangeListener( new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Check box "+arg0.getText().toString()+" is "+String.valueOf(arg1) , Toast.LENGTH_LONG).show();
}
} );
hin.setOnCheckedChangeListener( new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Check box "+arg0.getText().toString()+" is "+String.valueOf(arg1) , Toast.LENGTH_LONG).show();
}
} );
guj.setOnCheckedChangeListener( new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Check box "+arg0.getText().toString()+" is "+String.valueOf(arg1) , Toast.LENGTH_LONG).show();
}
} );
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="52dp"
android:text="Select Language"
android:textAppearance="?android:attr/textAppearanceLarge" />
<CheckBox
android:id="@+id/chkEnglish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="40dp"
android:text="English" />
<CheckBox
android:id="@+id/chkHindi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/chkEnglish"
android:layout_below="@+id/chkEnglish"
android:layout_marginTop="22dp"
android:text="Hindi" />
<CheckBox
android:id="@+id/chkGujarati"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/chkHindi"
android:layout_below="@+id/chkHindi"
android:layout_marginTop="30dp"
android:text="Gujarati" />
</RelativeLayout>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="52dp"
android:text="Select Language"
android:textAppearance="?android:attr/textAppearanceLarge" />
<CheckBox
android:id="@+id/chkEnglish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="40dp"
android:text="English" />
<CheckBox
android:id="@+id/chkHindi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/chkEnglish"
android:layout_below="@+id/chkEnglish"
android:layout_marginTop="22dp"
android:text="Hindi" />
<CheckBox
android:id="@+id/chkGujarati"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/chkHindi"
android:layout_below="@+id/chkHindi"
android:layout_marginTop="30dp"
android:text="Gujarati" />
</RelativeLayout>
Labels:
Android,
Mobile Computing
Subscribe to:
Post Comments (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- c (11)
- Configure Tomcat7 (2)
- CSS (3)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- install Tomcat (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- linux (8)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- shell script (33)
- unix (22)
- WTAD (34)
Blog Archive
-
▼
2013
(64)
-
▼
August
(17)
- Android AlertDialog with setMultiChoiceItems Example
- Android ProgressDialog Example
- Android AlertDialog setSingleChoiceItems Example
- Android AlertDialog List Example
- Android AlertDialog Example
- Android TimePickerDialog Example
- Android DatePickerDialog Example
- Android Button onClick Example that implements on...
- Android Button Example with onClickListener
- Android TimePicker Example with setOnTimeChangedLi...
- Android DatePicker example with onDateChanged list...
- An Android RadioGroup Example Programmatically
- Android RadioGroup Example using setOnCheckedChang...
- Android Checkbox Example
- android Checkbox setOnClickListener Example
- Android Checkbox setOnCheckedChangeListener Example
- command line arguments in linux shell script
-
▼
August
(17)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.
3 comments:
dwd
I want to connect MCQ to different checkboxes Lessonwise. Please assist if you can.
mail: studypoint4all@gmail.com
Informative blog and knowledgeable content. Keep sharing more blogs with us.
UI Development Course in Hyderabad
Uipath Training in Hyderabad
Python Course in Hyderabad
Mean Stack Development Course in Hyderabad
Post a Comment