<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="es">
	<id>https://manuais.iessanclemente.net/index.php?action=history&amp;feed=atom&amp;title=CheckBox</id>
	<title>CheckBox - Historial de revisiones</title>
	<link rel="self" type="application/atom+xml" href="https://manuais.iessanclemente.net/index.php?action=history&amp;feed=atom&amp;title=CheckBox"/>
	<link rel="alternate" type="text/html" href="https://manuais.iessanclemente.net/index.php?title=CheckBox&amp;action=history"/>
	<updated>2026-10-23T22:51:51Z</updated>
	<subtitle>Historial de revisiones de esta página en la wiki</subtitle>
	<generator>MediaWiki 1.46.2</generator>
	<entry>
		<id>https://manuais.iessanclemente.net/index.php?title=CheckBox&amp;diff=57128&amp;oldid=prev</id>
		<title>Angelfg en 08:07 28 jul 2015</title>
		<link rel="alternate" type="text/html" href="https://manuais.iessanclemente.net/index.php?title=CheckBox&amp;diff=57128&amp;oldid=prev"/>
		<updated>2015-07-28T08:07:55Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Página nueva&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Introdución==&lt;br /&gt;
*Un &amp;#039;&amp;#039;&amp;#039;CheckBox&amp;#039;&amp;#039;&amp;#039; permite ao usuario elixir unha ou máis opcións dentro dun conxunto.&lt;br /&gt;
[[Image:00_checkboxes.png]]&lt;br /&gt;
&lt;br /&gt;
*Este control ao igual que ToggleButton e Switch herda da clase &amp;#039;&amp;#039;&amp;#039;CompoundButton&amp;#039;&amp;#039;&amp;#039;, quen, á súa vez, herda da clase &amp;#039;&amp;#039;&amp;#039;Button&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
[[Image:00_Part_of_Android_View_Hierarchy.png|600px]]&lt;br /&gt;
*Imaxe obtida de: http://www.itcsolutions.eu/2011/08/27/android-tutorial-4-procedural-vs-declarative-design-of-user-interfaces&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Por tanto, funcionan da mesma maneira, pero ademais este control:&lt;br /&gt;
**Ten 2 estados (True/False), que podemos comprobar co método &amp;#039;&amp;#039;&amp;#039;isChecked ()&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Para xestionar os eventos podemos facelo da mesma forma que nos botóns.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Para usalo nun XML layout usar a etiqueta &amp;lt;CheckBox/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Referencias:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
**O control CheckBox: http://developer.android.com/reference/android/widget/CheckBox.html&lt;br /&gt;
**Introdución ao CheckBox: http://developer.android.com/guide/topics/ui/controls/checkbox.html&lt;br /&gt;
&lt;br /&gt;
==Caso práctico==&lt;br /&gt;
*Creamos un novo proxecto: &amp;#039;&amp;#039;&amp;#039;U2_10_CheckBox&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
*Imos crear unha aplicación na que o usuario indique as súas afeccións (&amp;quot;Aficiones&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;gallery caption=&amp;quot;CheckBox&amp;quot; widths=&amp;quot;350&amp;quot; heights=&amp;quot;300px&amp;quot; perrow=&amp;quot;2&amp;quot;&amp;gt;&lt;br /&gt;
Image:Android_2013_U2_10_CheckBox_01.jpg| Ao entrar na aplicación non hai ningunha marcada. &lt;br /&gt;
Image:Android_2013_U2_10_CheckBox_02.jpg| Cando se selecciona unha afección aparece unha mensaxe nunha caixa de texto indicando o que se seleccionou.&lt;br /&gt;
Image:Android_2013_U2_10_CheckBox_03.jpg| Cando se deselecciona unha afección aparece unha mensaxe nunha caixa de texto indicando o que se deseleccionou. &lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Layout xml===&lt;br /&gt;
&lt;br /&gt;
*Cada &amp;#039;&amp;#039;&amp;#039;CheckBox&amp;#039;&amp;#039;&amp;#039; chama a un método cando se marca ou desmarca ese CheckBox.&lt;br /&gt;
*O método é o mesmo para os tres.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; line highlight=&amp;quot;11,18,25&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;LinearLayout xmlns:android=&amp;quot;http://schemas.android.com/apk/res/android&amp;quot;&lt;br /&gt;
    android:layout_width=&amp;quot;match_parent&amp;quot;&lt;br /&gt;
    android:layout_height=&amp;quot;match_parent&amp;quot;&lt;br /&gt;
    android:orientation=&amp;quot;vertical&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;CheckBox&lt;br /&gt;
        android:id=&amp;quot;@+id/chk_informatica&amp;quot;&lt;br /&gt;
        android:layout_width=&amp;quot;wrap_content&amp;quot;&lt;br /&gt;
        android:layout_height=&amp;quot;wrap_content&amp;quot;&lt;br /&gt;
        android:onClick=&amp;quot;controlarAfeccions&amp;quot;&lt;br /&gt;
        android:text=&amp;quot;Informática&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;CheckBox&lt;br /&gt;
        android:id=&amp;quot;@+id/chk_ler&amp;quot;&lt;br /&gt;
        android:layout_width=&amp;quot;wrap_content&amp;quot;&lt;br /&gt;
        android:layout_height=&amp;quot;wrap_content&amp;quot;&lt;br /&gt;
        android:onClick=&amp;quot;controlarAfeccions&amp;quot;&lt;br /&gt;
        android:text=&amp;quot;Ler&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;CheckBox&lt;br /&gt;
        android:id=&amp;quot;@+id/chk_deporte&amp;quot;&lt;br /&gt;
        android:layout_width=&amp;quot;wrap_content&amp;quot;&lt;br /&gt;
        android:layout_height=&amp;quot;wrap_content&amp;quot;&lt;br /&gt;
        android:onClick=&amp;quot;controlarAfeccions&amp;quot;&lt;br /&gt;
        android:text=&amp;quot;Deportes&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;EditText&lt;br /&gt;
        android:id=&amp;quot;@+id/txt_resultado&amp;quot;&lt;br /&gt;
        android:layout_width=&amp;quot;match_parent&amp;quot;&lt;br /&gt;
        android:layout_height=&amp;quot;wrap_content&amp;quot;&lt;br /&gt;
        android:hint=&amp;quot;Resultado&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/LinearLayout&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Código Java===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot; line highlight=&amp;quot;25-33&amp;quot;&amp;gt;&lt;br /&gt;
package com.example.u2_10_checkbox;&lt;br /&gt;
&lt;br /&gt;
import android.app.Activity;&lt;br /&gt;
import android.os.Bundle;&lt;br /&gt;
import android.view.Menu;&lt;br /&gt;
import android.view.View;&lt;br /&gt;
import android.widget.CheckBox;&lt;br /&gt;
import android.widget.EditText;&lt;br /&gt;
&lt;br /&gt;
public class U2_10_CheckBox extends Activity {&lt;br /&gt;
&lt;br /&gt;
	@Override&lt;br /&gt;
	protected void onCreate(Bundle savedInstanceState) {&lt;br /&gt;
		super.onCreate(savedInstanceState);&lt;br /&gt;
		setContentView(R.layout.activity_u2_10__check_box);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	@Override&lt;br /&gt;
	public boolean onCreateOptionsMenu(Menu menu) {&lt;br /&gt;
		// Inflate the menu; this adds items to the action bar if it is present.&lt;br /&gt;
		getMenuInflater().inflate(R.menu.u2_10__check_box, menu);&lt;br /&gt;
		return true;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	public void controlarAfeccions(View view) {&lt;br /&gt;
		CheckBox check = (CheckBox) view;&lt;br /&gt;
		&lt;br /&gt;
		EditText caixa = (EditText) findViewById(R.id.txt_resultado);&lt;br /&gt;
		if (check.isChecked()) &lt;br /&gt;
			caixa.setText(&amp;quot;Marcaches: &amp;quot;  + check.getText());&lt;br /&gt;
		else&lt;br /&gt;
			caixa.setText(&amp;quot;Desmarcaches: &amp;quot;  + check.getText());&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Liña 25&amp;#039;&amp;#039;&amp;#039;, recibimos a Vista do elemento pulsado hai que facer un casting para convertelo ao tipo CheckBox.&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Liña 29&amp;#039;&amp;#039;&amp;#039;, comprobamos se se marcou ou desmarcou o control.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; -- [[Usuario:angelfg|Ángel D. Fernández González]] e [[Usuario:Carrion|Carlos Carrión Álvarez]] -- (2015).&lt;/div&gt;</summary>
		<author><name>Angelfg</name></author>
	</entry>
</feed>