0% found this document useful (0 votes)
40 views

Checkbox

The document contains an XML layout file defining a relative layout with three checkboxes for programming languages Python, PHP and Java. It also contains a Java class file that defines a MainActivity class with methods to get references to the checkboxes, check their states when a button is clicked, and display the states in toast messages.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Checkbox

The document contains an XML layout file defining a relative layout with three checkboxes for programming languages Python, PHP and Java. It also contains a Java class file that defines a MainActivity class with methods to get references to the checkboxes, check their states when a button is clicked, and display the states in toast messages.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

<?xml version="1.0" encoding="utf-8"?

>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<CheckBox
android:id="@+id/python"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="Python" />

<CheckBox
android:id="@+id/php"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_below="@+id/python"

android:text="PHP" />

<CheckBox
android:id="@+id/java"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/php"

android:text="Java" />

<Button
android:id="@+id/boton_guardar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/java"
android:backgroundTint="#0C80B5"
android:onClick="loguearCheckbox"
android:text="Guardar" />
</RelativeLayout>

-----------------------------------------------------------------------------------
--------------------------------

package com.example.spinner;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements


AdapterView.OnItemSelectedListener{
private CheckBox Python;
private CheckBox Java;
private CheckBox PHP;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Python = (CheckBox) findViewById(R.id.python);


PHP = (CheckBox) findViewById(R.id.php);
Java = (CheckBox) findViewById(R.id.java);
}

public void loguearCheckbox(View v) {


String s = "Estado: " + (Python.isChecked() ? "Python True" : "Python
False");
Toast.makeText(this, s, Toast.LENGTH_LONG).show();
String p = "Estado: " + (PHP.isChecked() ? "PHP True" : "PHP False");
Toast.makeText(this, p, Toast.LENGTH_LONG).show();
String j = "Estado: " + (Java.isChecked() ? "Java True" : "Java False");
Toast.makeText(this, j, Toast.LENGTH_LONG).show();
}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long
id) {

@Override
public void onNothingSelected(AdapterView<?> parent) {

You might also like