0% found this document useful (0 votes)
56 views4 pages

Code Nam

The document contains code for an Android application that allows a user to enter a year number, select between the Lunar or Solar calendar systems, and displays the corresponding Lunar or Solar year. It includes Java code to define activities, buttons, text fields and logic to convert the year number between the two calendar systems. The XML layout code defines the user interface with input fields, radio buttons and a display text view.

Uploaded by

Nhất Jocelyn
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)
56 views4 pages

Code Nam

The document contains code for an Android application that allows a user to enter a year number, select between the Lunar or Solar calendar systems, and displays the corresponding Lunar or Solar year. It includes Java code to define activities, buttons, text fields and logic to convert the year number between the two calendar systems. The XML layout code defines the user interface with input fields, radio buttons and a display text view.

Uploaded by

Nhất Jocelyn
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/ 4

//file java

package com.example.beta1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

EditText edt;
RadioButton rdo1 ;
RadioButton rdo2;
Button btnSubmit;
TextView hienthi;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

edt = (EditText) findViewById(R.id.editTextNumber);


rdo1 = (RadioButton) findViewById(R.id.radioButton7) ;
rdo2 = (RadioButton) findViewById(R.id.radioButton8);
btnSubmit = (Button) findViewById(R.id.button6);
hienthi = (TextView) findViewById(R.id.textView6) ;
btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int nam = Integer.parseInt(edt.getText().toString());
if(rdo1.isChecked()){
String can = " ",chi = " ";
switch (nam%10){
case 0 :
can = "canh";
break;
case 1 :
can = "tan";
break;
case 2 :
can = "nham";
break;
case 3 :
can = "quy";
break;
case 4 :
can = "giap";
break;
case 5 :
can = "at";
break;
case 6 :
can = "binh";
break;
case 7 :
can = "dinh";
break;
case 8 :
can = "mau";
break;
case 9 :
can = "ky";
break;

}
switch (nam % 12){
case 0 :
chi = "than";
break;
case 1 :
chi = "dau";
break;
case 2 :
chi = "tuat";
break;
case 3 :
chi = "hoi";
break;
case 4 :
chi = "ty";
break;
case 5 :
chi = "suu";
break;
case 6 :
chi = "dan";
break;
case 7 :
chi = "mao";
break;
case 8 :
chi = "thin";
break;
case 9 :
chi = "ty";
break;
case 10 :
chi = "ngo";
break;
case 11 :
chi = "mui";
break;

hienthi.setText("am lich : " + can + " " + chi);


}
if(rdo2.isChecked()){
hienthi.setText("duong lich : " + String.valueOf(nam));
}

}
});
}
}

// file xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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">

<EditText
android:id="@+id/editTextNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:ems="10"
android:hint="Nhap mot so n"
android:inputType="number"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.452"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="SpeakableTextPresentCheck" />

<RadioGroup
android:id="@+id/radioGroup2"
android:layout_width="322dp"
android:layout_height="123dp"
android:layout_marginTop="32dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.364"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextNumber">

<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="chon hien thi" />

<RadioButton
android:id="@+id/radioButton7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Nam am lich"
android:textSize="20sp"
/>

<RadioButton
android:id="@+id/radioButton8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Nam duong lich"
android:textSize="20sp"
/>
</RadioGroup>

<Button
android:id="@+id/button6"
android:layout_width="268dp"
android:layout_height="67dp"
android:layout_marginTop="24dp"
android:text="ket qua"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.419"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/radioGroup2" />

<TextView
android:id="@+id/textView6"
android:layout_width="342dp"
android:layout_height="86dp"
android:layout_marginTop="40dp"
android:text="ket qua"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.478"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button6" />
</androidx.constraintlayout.widget.ConstraintLayout>

You might also like