activity_main.xml:
showButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(check.isChecked()){
Toast.makeText(getApplicationContext(), "Checked", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(), "UnChecked", Toast.LENGTH_LONG).show();
}
}
});
}
}
<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" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="87dp"
android:layout_marginTop="54dp"
android:text="CheckBox" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Show" />
</RelativeLayout>
public class MainActivity extends Activity {
CheckBox check;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
check = (CheckBox)findViewById(R.id.checkBox1);
check.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
if(arg0.isChecked()){
check.setText("Checked");
}else{
check.setText("UnChecked");
}
}
});
CheckBox check;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
check = (CheckBox)findViewById(R.id.checkBox1);
check.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
if(arg0.isChecked()){
check.setText("Checked");
}else{
check.setText("UnChecked");
}
}
});
------------------------------------------------------------------------------------------------------
public class MainActivity extends Activity {
CheckBox check;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
check = (CheckBox)findViewById(R.id.checkBox1);
Button showButton = (Button)findViewById(R.id.button1);
CheckBox check;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
check = (CheckBox)findViewById(R.id.checkBox1);
Button showButton = (Button)findViewById(R.id.button1);
showButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(check.isChecked()){
Toast.makeText(getApplicationContext(), "Checked", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(), "UnChecked", Toast.LENGTH_LONG).show();
}
}
});
}
}
No comments:
Post a Comment