User Interface. CheckBox

În cadrul acestui tutorial vei învăța cum se utilizează CheckBox  pentru a prelua input de la utilizator. De asemenea vei afla cum poate fi customizat acest control.

checkbox

1. Adăugare control în xml-ul asignat layout-ului


<CheckBox

android:id="@+id/checkBox1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="CheckBox" />

2. Preluare valoare în mod programatic

CheckBox checkBox1 = (CheckBox) findViewById(R.id.checkBox1);</pre>
if (checkBox.isChecked()) { /* your code */}

3. Evenimente asociate

checkBox1.setOnClickListener(new OnClickListener()
{
@Override public void onClick(View v)
{
//is checked?
if (((CheckBox) v).isChecked())
{
Toast.makeText(MyAndroidAppActivity.this, "CheckBox checked :)", Toast.LENGTH_LONG).show();
}
}
});
Advertisements
User Interface. CheckBox

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s