Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Android App Using concept of CheckBox

Hey this is the sample android application based on the checkbox, I’m sharing this code for beginner’s to learn practical things to get started with android development. By the way output of this android application is attached in the feature image above.

activity_main.xml


 

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;
    }
    
}

The post Android App Using concept of CheckBox appeared first on Junaid Shahid | P-Blogger.



This post first appeared on Junaid Shahid | P-Blogger, please read the originial post: here

Share the post

Android App Using concept of CheckBox

×

Subscribe to Junaid Shahid | P-blogger

Get updates delivered right to your inbox!

Thank you for your subscription

×