Checkbox Example

Checkbox is used for two states such as checked or unchecked state. This button keeps our answering work as simple.

actvity_main.xml

This xml shows three checkbox in listview shape with one button in bottom place.





    

    

    

    

MainActivity.java

This activity shows selected checkbox text as message.

package com.example.icowboysradio.myapplication;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;

public class MainActivity extends Activity {
    CheckBox india,america,russia;
    Button btnSubmit;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        addListenerOnButtonClick();
    }
    public void addListenerOnButtonClick(){
         
        india=(CheckBox)findViewById(R.id.check1);
        america=(CheckBox)findViewById(R.id.check2);
        russia=(CheckBox)findViewById(R.id.check3);
        btnSubmit=(Button)findViewById(R.id.btn_submit);
        
        btnSubmit.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View view) {
                StringBuilder result = new StringBuilder();
                result.append("Choosed Country:");
                if(india.isChecked()){
                    result.append("\n India");
                }
                if(america.isChecked()){
                    result.append("\nRussia");
                }
                if(russia.isChecked()){
                    result.append("\nAmerica");
                }
                Toast.makeText(getApplicationContext(), result.toString(), Toast.LENGTH_LONG).show();
            }

        });
    }


}

Affect of Color Property on Borders and Oulines

The color property is not just for text content, but for anything in the foreground that takes a color value. For instance, if border-color or outline-color value hasn’t been defined explicitly for the element, the color value will be used instead.

[css]

p.one {
color: #0000ff;
border: 2px solid;
}
p.two {
color: #00ff00;
outline: 2px solid;
}

[/css]