D:\chandreadymadeshop\app\src\main\res\layout\activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/chandra">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/TV1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Whatever you Want !!"
android:textColor="@android:color/holo_red_dark"
android:textSize="20sp" />
<CheckBox
android:id="@+id/CB1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="Silk Saree"
android:textColor="#F00" />
<CheckBox
android:id="@+id/CB2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="Synthetic Saree"
android:textColor="#F0F" />
<CheckBox
android:id="@+id/CB3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="Cotton Saree"
android:textColor="#F00F" />
<CheckBox
android:id="@+id/CB4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="Jute Saree"
android:textColor="#ff00" />
<Button
android:layout_width="314dp"
android:layout_height="wrap_content"
android:text="PRESS IT"
android:id="@+id/btn"
android:background="#f8f40b"
android:textColor="#fd0707"/>
</LinearLayout>
</ScrollView>
-----------------------------------------------------------------------------
D:\chandreadymadeshop\app\src\main\java\com\ldc\chandreadymadeshop\MainActivity.java
package com.ldc.chandreadymadeshop; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { Button btn; CheckBox cb1, cb2, cb3,cb4; TextView v1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); cb1=(CheckBox) findViewById(R.id.CB1); cb2=(CheckBox) findViewById(R.id.CB2); cb3=(CheckBox) findViewById(R.id.CB3); cb4=(CheckBox) findViewById(R.id.CB4); btn=(Button) findViewById(R.id.btn); v1=(TextView) findViewById(R.id.TV1); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String txt=" "; if(cb1.isChecked() == true ) txt=(String)cb1.getText(); if(cb2.isChecked() == true ) txt=txt+", "+(String)cb2.getText(); if(cb3.isChecked() == true ) txt=txt+" , "+(String)cb3.getText(); if(cb4.isChecked() == true ) txt=txt+" , "+(String)cb4.getText(); v1.setText("You have Selected "+txt); if(cb1.isChecked() == false && cb2.isChecked()==false && cb3.isChecked()==false && cb4.isChecked()==false) { Toast.makeText(getBaseContext(),"OOPS! you haven`t selected anythng (: (: ",Toast.LENGTH_LONG).show(); v1.setText("You haven't Selected (: (; (: "+txt); } } }); } } ----------------------------------------------------------------------------------------
No comments:
Post a Comment