import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
public class ChckboxActivity extends Activity {
/** Called when the activity is first created. */
Button b ;
CheckBox c1,c2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b = (Button)findViewById(R.id.button1);
c1 = (CheckBox)findViewById(R.id.checkBox1);
c2 = (CheckBox)findViewById(R.id.checkBox2);
}
public void show(View V)
{if(c1.isChecked()==true&&c2.isChecked()==false)
{
//i used both toast n button to display message..
Toast.makeText(getBaseContext(), "awesum", 5000).show();
//b.setText("u r an awesum");
}
if(c1.isChecked()==false&&c2.isChecked()==true)
{
Toast.makeText(getBaseContext(), u r superb", 5000).show();
// b.setText("u r superb");
}
if(c1.isChecked()==true&&c2.isChecked()==true)
{
Toast.makeText(getBaseContext(), "u r awesum n superb", 5000).show();
// b.setText("u r awesum n superb");
}
if(c1.isChecked()==false&&c2.isChecked()==false)
{
Toast.makeText(getBaseContext(), "select any option", 5000).show();
// b.setText("atleast select any option");
}
}
}
XML FILE
<?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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="awesum" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="superb" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="show"
android:text="click" />
</LinearLayout>
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
public class ChckboxActivity extends Activity {
/** Called when the activity is first created. */
Button b ;
CheckBox c1,c2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b = (Button)findViewById(R.id.button1);
c1 = (CheckBox)findViewById(R.id.checkBox1);
c2 = (CheckBox)findViewById(R.id.checkBox2);
}
public void show(View V)
{if(c1.isChecked()==true&&c2.isChecked()==false)
{
//i used both toast n button to display message..
Toast.makeText(getBaseContext(), "awesum", 5000).show();
//b.setText("u r an awesum");
}
if(c1.isChecked()==false&&c2.isChecked()==true)
{
Toast.makeText(getBaseContext(), u r superb", 5000).show();
// b.setText("u r superb");
}
if(c1.isChecked()==true&&c2.isChecked()==true)
{
Toast.makeText(getBaseContext(), "u r awesum n superb", 5000).show();
// b.setText("u r awesum n superb");
}
if(c1.isChecked()==false&&c2.isChecked()==false)
{
Toast.makeText(getBaseContext(), "select any option", 5000).show();
// b.setText("atleast select any option");
}
}
}
XML FILE
<?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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="awesum" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="superb" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="show"
android:text="click" />
</LinearLayout>
No comments:
Post a Comment