Cara menampilkan CheckBox di android studio

Tutorial Android

Cara menampilkan CheckBox di android studio

activity_main.xml

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical" android:layout_width="match_parent"

android:layout_height="match_parent">

<CheckBox

android:id="@+id/chkCricket"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:padding="10dp"

android:layout_marginTop="150dp"

android:layout_marginLeft="100dp"

android:text="Cricket"

/>

<CheckBox

android:id="@+id/chkFootball"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:padding="10dp"

android:layout_marginLeft="100dp"

android:text="Football"

/>

<CheckBox

android:id="@+id/chkHockey"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:padding="10dp"

android:layout_marginLeft="100dp"

android:text="Hockey"

/>

<Button

android:id="@+id/getBtn"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="100dp"

android:background="#bf00ff"

android:textColor="#FFFFFF"

android:minHeight="30dp"

android:text="Submit" />

</LinearLayout>

 

MainActivity.java

package com.example.chcekboxexample;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.CheckBox;

public class MainActivity extends AppCompatActivity {

CheckBox android, java, angular, python;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

android = (CheckBox)findViewById(R.id.chkCricket);

java = (CheckBox)findViewById(R.id.chkFootball);

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

Button btn = (Button)findViewById(R.id.getBtn);

}

}

 

 

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *