MainActivity.java
package com.thistimebd.web.checkbox;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private CheckBox milkCheakBox, sugarCheckBox, waterCheckBox;
private Button showButton;
private TextView resultTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
milkCheakBox=(CheckBox) findViewById(R.id.milkCheckBoxId);
sugarCheckBox=(CheckBox) findViewById(R.id.sugarCheckBoxId);
waterCheckBox=(CheckBox) findViewById(R.id.waterCheckBoxId);
showButton=(Button) findViewById(R.id.showButtonId);
resultTextView=findViewById(R.id.resultTextViewId);
showButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringBuilder stringBuilder=new StringBuilder();
if(milkCheakBox.isChecked()){
String value=milkCheakBox.getText().toString();
stringBuilder.append(value+ " is ordered"+"");
} if(sugarCheckBox.isChecked()){
String value=sugarCheckBox.getText().toString();
stringBuilder.append(value+ " is ordered"+"");
} if(waterCheckBox.isChecked()){
String value=waterCheckBox.getText().toString();
stringBuilder.append(value+ " is ordered"+"");
}
resultTextView.setText(stringBuilder);
}
});
}
}
string.xml
------------------------------------------------------------------
activity_main.xml
----------------
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#30b788"
android:padding="10dp"
android:orientation="vertical"
tools:context="com.thistimebd.web.checkbox.MainActivity">
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_text"
android:textSize="20sp"
android:textStyle="bold"
/>
android:id="@+id/milkCheckBoxId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/milk_text"
android:textSize="20sp"
/>
android:id="@+id/sugarCheckBoxId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/sugar_text"
android:textSize="20sp"
/>
android:id="@+id/waterCheckBoxId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/water_text"
android:textSize="20sp"
/>
android:id="@+id/showButtonId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_text"
android:textSize="20sp"
android:textStyle="bold"
/>
android:id="@+id/resultTextViewId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
/>
thistimebd Bangladesh Live online newsportal, education, Lifestyle, Health, Photography, gif image etc.
Make your own name or company name website | contact: thistimebd24@gmail.com
Copyright © 2020-2024 News Portal in Bangladesh - THISTIMEBD.COM. ALL Rights Reserved.