Android App Using concept of CheckBox

      No Comments on Android App Using concept of CheckBox

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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Q1- Which of the following is an input device?" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="16dp"
        android:text="A" />

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView2"
        android:layout_alignBottom="@+id/textView2"
        android:layout_marginLeft="19dp"
        android:layout_toRightOf="@+id/textView2"
        android:text="Printer" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView2"
        android:layout_below="@+id/checkBox1"
        android:layout_marginTop="22dp"
        android:text="B" />

    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView3"
        android:layout_alignBottom="@+id/textView3"
        android:layout_alignLeft="@+id/checkBox1"
        android:text="Monitor" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView3"
        android:layout_below="@+id/checkBox2"
        android:layout_marginTop="26dp"
        android:text="C" />

    <CheckBox
        android:id="@+id/checkBox3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView4"
        android:layout_alignBottom="@+id/textView4"
        android:layout_alignLeft="@+id/checkBox2"
        android:text="Keyboard" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView4"
        android:layout_below="@+id/checkBox3"
        android:layout_marginTop="28dp"
        android:text="D" />

    <CheckBox
        android:id="@+id/checkBox4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView5"
        android:layout_alignBottom="@+id/textView5"
        android:layout_alignLeft="@+id/checkBox3"
        android:text="Plotter" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView5"
        android:layout_below="@+id/checkBox4"
        android:layout_marginTop="18dp"
        android:text="Next" />

</RelativeLayout>

activityMain.java



package com.example.design;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.CheckBox;
import android.widget.TextView;

public class MainActivity extends Activity 
{
	Button b1;
	TextView t1;
	int count=0;
	CheckBox Printer,Monitor,Keyboard,Plotter;
	String[] array = {"Monitor","Keyboard","Mouse","Light Pen"};
	String[] array1= {"mouse","Monitor","Hard Disk","Motherboard"};
	String[] array2= {"Linux","Hindi","Java","Unix"};
	String[] array3= {"PHP","HTML","Unix","C++"};
	String[] array4={"Q2- Which of the following is an output device?",
			"Q3- Which part of the computer is known as the brain of the computer?",
			"Q4- Which of the following is a computer language?",
			"Q5- Which of the following is an operating system?"};
	
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        addListenerOnButtonClick();
        
    }
        public void addListenerOnButtonClick()
        {    	
        	b1=(Button)findViewById(R.id.button1);
            Printer=(CheckBox)findViewById(R.id.checkBox1);
        	Monitor=(CheckBox)findViewById(R.id.checkBox2);
        	Keyboard=(CheckBox)findViewById(R.id.checkBox3);
        	Plotter=(CheckBox)findViewById(R.id.checkBox4);
        	t1=(TextView)findViewById(R.id.textView1);
        	
        	b1.setOnClickListener(new OnClickListener()
        	{
        		
        		@Override
        		public void onClick(View view)
        		{
        			 count=count+1;
        		
            			
        			
        if(count==1)
        {
      
        	t1.setText(String.valueOf(array4[0]));
            	Printer.setText(array[0]);
               Monitor.setText(String.valueOf(array[1]));
                Keyboard.setText(String.valueOf(array[2]));
                Plotter.setText(String.valueOf(array[3]));
           
      
        }
        
        if(count==2)
        {
      
        	     
        	t1.setText(String.valueOf(array4[1]));
            	
            	Printer.setText(array1[0]);
               Monitor.setText(String.valueOf(array1[1]));
                Keyboard.setText(String.valueOf(array1[2]));
                Plotter.setText(String.valueOf(array1[3]));
           
      
        }
        
        if(count==3)
        {
        	t1.setText(String.valueOf(array4[2]));
            	String s1=array2[0];
            	Printer.setText(array2[0]);
               Monitor.setText(String.valueOf(array2[1]));
                Keyboard.setText(String.valueOf(array2[2]));
                Plotter.setText(String.valueOf(array2[3]));
           
      
        }
        
        
        if(count==4)
        {
        	t1.setText(String.valueOf(array4[3]));
            	String s1=array3[0];
            	Printer.setText(array3[0]);
               Monitor.setText(String.valueOf(array3[1]));
                Keyboard.setText(String.valueOf(array3[2]));
                Plotter.setText(String.valueOf(array3[3]));
           
      
        }
                
        		}
        });
}
    


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}

OUTPUT:-

checkbox

Leave a Reply

Your email address will not be published. Required fields are marked *