Bài 1 : Đổi độ C -> F và ngược lại
Code XML:
<? ?>xml version="1.0" encoding="utf-8"
<LinearLayout 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"
="vertical"android:orientation
=".MainActivity"tools:context
="10dp"android:layout_margin
android:padding="5dp">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
="wrap_content"android:layout_height
android:text="Farenheit"
="@color/black"android:textColor
="25dp" android:textSize />
<EditText
android:id="@+id/edtF"
android:layout_width="match_parent"
="wrap_content"android:layout_height
="10"android:ems
="textPersonName"android:inputType
android:layout_marginTop="10dp"/>
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
="wrap_content"android:layout_height
="Celsius"android:text
="@color/black"android:textColor
="25dp"android:textSize
/>
<EditText
android:id="@+id/edtC"
android:layout_width="match_parent"
="wrap_content"android:layout_height
="10"android:ems
="textPersonName"android:inputType
="10dp"android:layout_marginTop
/>
<LinearLayout
android:layout_width="match_parent"
="wrap_content"android:layout_height
android:orientation="horizontal"
android:layout_marginTop="10dp">
<Button
android:id="@+id/btnFC"
="wrap_content"android:layout_width
="wrap_content"android:layout_height
="1"android:layout_weight
="Convert to Celsius" android:text />
<Button
android:id="@+id/btnCF"
="wrap_content"android:layout_width
="wrap_content"android:layout_height
="1"android:layout_weight
="Convert to Fahrenheit" android:text />
</LinearLayout>
<Button
android:id="@+id/btnClear"
android:layout_width="match_parent"
="wrap_content"android:layout_height
="Clear"android:text
android:layout_marginTop="10dp"/>
</LinearLayout>
Code Java:
package ;edu.huflit.btonline_tuan1
import ;android.support.v7.app.AppCompatActivity
import ;android.os.Bundle
import ;android.text.Editable
import ;android.view.View
import ;android.widget.Button
import ;android.widget.EditText
import ;android.widget.TextView
public class extends MainActivity AppCompatActivity {
//View
EditText edtF, ;edtC
, , ;Button btnCF btnFC btnClear
@Override
protected void onCreate(Bundle savedInstanceState) {
super ;.onCreate(savedInstanceState)
;setContentView(R.layout. )activity_main
// Ánh sạ ID
edtC = findViewById(R.id.edtC);
;edtF = findViewById(R.id.edtF)
;btnCF = findViewById(R.id.btnCF)
;btnFC = findViewById(R.id.btnFC)
//Xử lý click
btnCF.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
doC = Integer.int parseInt( .getText().toString())edtC ;
double ;doF = doC* + 1.8 32
;String text = doF + "Độ F"
;edtF.setText(text)
}
});
new btnFC.setOnClickListener( View.OnClickListener() {
@Override
public void onClick(View view) {
doF = Integer.int parseInt( .getText().toString())edtF ;
double ;doC = (doF-32 1.8)/
;edtC.setText(doC+ "")
}
});
new btnClear.setOnClickListener( View.OnClickListener() {
@Override
public void onClick(View view) {
edtC.setText( )"" ;
;edtF.setText( )""
}
});
}
}
Bài 2 : Tính BMI
Code XML :
<? ?>xml version="1.0" encoding="utf-8"
<LinearLayout 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"
="vertical"android:orientation
=".MainActivity" tools:context >
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
="62dp"android:layout_height
="#268112"android:background
="center"android:gravity
="Chương trình tính chỉ số BMI"android:text
android:textColor="@color/white"
="25dp"android:textSize
android:textStyle="bold"/>
<LinearLayout
android:layout_width="match_parent"
="wrap_content"android:layout_height
android:orientation="horizontal">
<TextView
android:id="@+id/textView2"
="wrap_content"android:layout_width
="wrap_content"android:layout_height
="1"android:layout_weight
="Nhập tên : "android:text
android:textSize="18dp"/>
<EditText
android:id="@+id/edtTen"
="wrap_content"android:layout_width
="wrap_content"android:layout_height
="1"android:layout_weight
="10"android:ems
="textPersonName"android:inputType
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
="wrap_content"android:layout_height
android:orientation="horizontal">
<TextView
android:id="@+id/textView3"
="93dp"android:layout_width
="wrap_content"android:layout_height
="1"android:layout_weight
="Chiều cao : "android:text
android:textSize="18dp"/>
<EditText
android:id="@+id/edtChieuCao"
="wrap_content"android:layout_width
="wrap_content"android:layout_height
="1"android:layout_weight
="10"android:ems
="textPersonName"android:inputType
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
="wrap_content"android:layout_height
android:orientation="horizontal">
<TextView
android:id="@+id/textView4"
="93dp"android:layout_width
="wrap_content"android:layout_height
="1"android:layout_weight
="Cân nặng : "android:text
android:textSize="18dp"/>
<EditText
android:id="@+id/edtCanNang"
="wrap_content"android:layout_width
="wrap_content"android:layout_height
="1"android:layout_weight
="10"android:ems
="textPersonName"android:inputType
/>
</LinearLayout>
<Button
android:id="@+id/btnKetQua"
android:layout_width="match_parent"
="wrap_content"android:layout_height
="Tính BMI"android:text
="#FF0000"android:textColor
="#8C8C8C"android:background
="center"android:gravity
="30dp"android:textSize
="bold"android:textStyle
/>
<Button
android:id="@+id/btnXoa"
android:layout_width="match_parent"
="wrap_content"android:layout_height
="Xoá"android:text
="#FF0000"android:textColor
="#8C8C8C"android:background
="center"android:gravity
="30dp"android:textSize
="bold"android:textStyle
android:layout_marginTop="10dp"/>
<LinearLayout
android:layout_width="match_parent"
="wrap_content"android:layout_height
android:orientation="horizontal"
android:layout_marginTop="10dp">
<TextView
android:id="@+id/textView6"
="98dp"android:layout_width
="wrap_content"android:layout_height
="1"android:layout_weight
="BMI = "android:text
android:textSize="18dp"/>
<TextView
android:id="@+id/tvBMI"
="wrap_content"android:layout_width
="wrap_content"android:layout_height
="1"android:layout_weight
="10"android:ems
="textPersonName"android:inputType
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<TextView
android:id="@+id/textView7"
="99dp"android:layout_width
="wrap_content"android:layout_height
="1"android:layout_weight
="Chuẩn đoán : "android:text
android:textSize="18dp"/>
<TextView
android:id="@+id/tvChuanDoan"
="wrap_content"android:layout_width
="wrap_content"android:layout_height
="1"android:layout_weight
="10"android:ems
="textPersonName"android:inputType
/>
</LinearLayout>
</LinearLayout>
Code Java:
package ;edu.huflit.ex2
import ;android.support.v7.app.AppCompatActivity
import ;android.os.Bundle
import ;android.view.View
import ;android.widget.Button
import ;android.widget.EditText
import ;android.widget.TextView
public class extends MainActivity AppCompatActivity {
EditText edtTen, , ;edtCanNang edtChieuCao
, ;Button btnKetQua btnXoa
, ;TextView tvBMI tvChuanDoan
@Override
protected void onCreate(Bundle savedInstanceState) {
super ;.onCreate(savedInstanceState)
;setContentView(R.layout. )activity_main
;edtTen = findViewById(R.id.edtTen)
;edtCanNang = findViewById(R.id.edtCanNang)
;edtChieuCao = findViewById(R.id.edtChieuCao)
;btnKetQua = findViewById(R.id.btnKetQua)
;tvBMI = findViewById(R.id.tvBMI)
;tvChuanDoan = findViewById(R.id.tvChuanDoan)
;btnXoa = findViewById(R.id.btnXoa)
new btnKetQua.setOnClickListener( View.OnClickListener() {
@Override
public void onClick(View v) {
cannang = double
Double. ( .getText().toString())parseDouble edtCanNang ;
double chieucao =
Double. ( .getText().toString())parseDouble edtChieuCao ;
;Double BMI = cannang / (chieucao * chieucao)
// Xử lý BMI để làm tròn nó
BMI = ( ) Math.double round(BMI* )/100 100;
;tvBMI tvBMI.setText( .getText()+ BMI.toString())
//Xử lý thông số BMI
if(BMI < ) 18 tvChuanDoan.setText("Người gấy");
else if (BMI <= && BMI >= ) 24.9 18 tvChuanDoan.setText("Người
bình thường");
else if (BMI <= && BMI >= ) 29.9 25 tvChuanDoan.setText("Người
béo phì độ I");
else if (BMI <= && BMI >= ) 34.9 30 tvChuanDoan.setText("Người
béo phì cấp độ II");
else if (BMI > ) 35 tvChuanDoan.setText("Người béo phì cấp độ
III");
}
});
new btnXoa.setOnClickListener( View.OnClickListener() {
@Override
public void onClick(View v) {
edtCanNang.setText( )"" ;
;edtChieuCao.setText( )""
;tvBMI.setText( )""
;tvChuanDoan.setText( )""
}
});
}
}
Bài 3 : ListView
Code XML:
<? ?>xml version="1.0" encoding="utf-8"
<LinearLayout 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"
="vertical"android:orientation
=".MainActivity"tools:context
android:padding="5dp">
<ListView
android:id="@+id/lvDiaDanh"
android:layout_width="match_parent"
="256dp" android:layout_height />
<ImageView
android:id="@+id/img"
android:layout_width="match_parent"
="wrap_content"android:layout_height
="@tools:sample/avatars" tools:srcCompat />
<EditText
android:id="@+id/edtTenDiaDanh"
android:layout_width="match_parent"
="wrap_content"android:layout_height
="30dp"android:layout_marginTop
="10"android:ems
="nhập tên địa danh"android:hint
="textPersonName" android:inputType />
<LinearLayout
android:layout_width="match_parent"
="44dp"android:layout_height
android:orientation="horizontal">
<Button
android:id="@+id/btnThemAnh"
="wrap_content"android:layout_width
="wrap_content"android:layout_height
="1"android:layout_weight
="Ảnh..." android:text />
<Button
android:id="@+id/btnThem"
="wrap_content"android:layout_width
="wrap_content"android:layout_height
="1"android:layout_weight
="Thêm" android:text />
</LinearLayout>
</LinearLayout>
Code Java:
package ;edu.huflit.ex3
import ;androidx.appcompat.app.AppCompatActivity
import ;android.os.Bundle
import ;android.view.View
import ;android.widget.AdapterView
import ;android.widget.ArrayAdapter
import ;android.widget.Button
import ;android.widget.EditText
import ;android.widget.ImageButton
import ;android.widget.ImageView
import ;android.widget.ListView
import ;android.widget.Toast
import ;java.util.ArrayList
public class extends MainActivity AppCompatActivity {
Button btnThemAnh, ;btnThemDiaDanh
;EditText edtTenDiaDanh
;ImageView img
;ListView listView
;ArrayList<String> arrayList
;ArrayAdapter<String> arrayAdapter

Preview text:

Bài 1 : Đổi độ C -> F và ngược lại Code XML:
<?xml version="1.0" encoding ?> ="utf-8"
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 ="vertical" :orientation tools =".MainActivity" :context android:layout_margin="10dp" android:padding="5dp"> android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Farenheit"
android:textColor="@color/black" android:textSize="25dp" /> android:id="@+id/edtF"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:ems="10"
android:inputType="textPersonName"
android:layout_marginTop="10dp"/> android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Celsius"
android:textColor="@color/black" android:textSize="25dp" /> android:id="@+id/edtC"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:ems="10"
android:inputType="textPersonName"
android:layout_marginTop="10dp" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"> android:id="@+id/btnFC"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:text="Convert to Celsius" /> android:id="@+id/btnCF"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:text="Convert to Fahrenheit" /> android:id="@+id/btnClear"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Clear"
android:layout_marginTop="10dp"/> Code Java:
package edu.huflit.btonline_tuan1; import ;
android.support.v7.app.AppCompatActivity import android.os.Bundle; import android.text.Editable; import android.view.View; import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity { //View EditText edtF, edtC; Button btnCF, btnFC, ; btnClear @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); // Ánh sạ ID
edtC = findViewById(R.id.edtC);
edtF = findViewById(R.id.edtF);
btnCF = findViewById(R.id.btnCF);
btnFC = findViewById(R.id.btnFC); //Xử lý click
btnCF.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View view) {
int doC = Integer.parseInt(edtC.getText().toString()); double doF = doC* + 1.8 32;
String text = doF + "Độ F"; edtF.setText(text); } });
btnFC.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View view) {
int doF = Integer.parseInt(edtF.getText().toString()); double doC = (doF-32)/1.8; edtC.setText(doC+ ""); } });
btnClear.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View view) { edtC.setText(""); edtF.setText(""); } }); } } Bài 2 : Tính BMI Code XML :
<?xml version="1.0" encoding ?> ="utf-8"
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:orientation="vertical"
tools:context=".MainActivity" > android:id="@+id/textView"
android:layout_width="match_parent" android:layout_height="62dp" android:background="#268112" android:gravity="center"
android:text="Chương trình tính chỉ số BMI"
android:textColor="@color/white" ="25dp" android:textSize android:textStyle="bold"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> android:id="@+id/textView2" ="wrap_content" android:layout_width
android:layout_height="wrap_content" android:layout_weight="1" ="Nhập tên : " android:text android:textSize="18dp"/> android:id="@+id/edtTen" ="wrap_content" android:layout_width
android:layout_height="wrap_content" android:layout_weight="1" android:ems="10"
android:inputType="textPersonName" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> android:id="@+id/textView3" ="93dp" android:layout_width
android:layout_height="wrap_content" android:layout_weight="1" ="Chiều cao : " android:text android:textSize="18dp"/> android:id="@+id/edtChieuCao" ="wrap_content" android:layout_width
android:layout_height="wrap_content" android:layout_weight="1" android:ems="10"
android:inputType="textPersonName" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> android:id="@+id/textView4" ="93dp" android:layout_width
android:layout_height="wrap_content" android:layout_weight="1" ="Cân nặng : " android:text android:textSize="18dp"/> android:id="@+id/edtCanNang" ="wrap_content" android:layout_width
android:layout_height="wrap_content" android:layout_weight="1" android:ems="10"
android:inputType="textPersonName" /> android:id="@+id/btnKetQua"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Tính BMI" android:textColor="#FF0000" android:background="#8C8C8C" android:gravity="center" ="30dp" android:textSize android:textStyle="bold" /> android:id="@+id/btnXoa"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Xoá" android:textColor="#FF0000" android:background="#8C8C8C" android:gravity="center" ="30dp" android:textSize android:textStyle="bold"
android:layout_marginTop="10dp"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"> android:id="@+id/textView6" ="98dp" android:layout_width
android:layout_height="wrap_content" android:layout_weight="1" ="BMI = " android:text android:textSize="18dp"/> android:id="@+id/tvBMI" ="wrap_content" android:layout_width
android:layout_height="wrap_content" android:layout_weight="1" android:ems="10"
android:inputType="textPersonName" />
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginTop="10dp"> android:id="@+id/textView7" ="99dp" android:layout_width
android:layout_height="wrap_content" android:layout_weight="1" ="Chuẩn đoán : " android:text android:textSize="18dp"/> android:id="@+id/tvChuanDoan" ="wrap_content" android:layout_width
android:layout_height="wrap_content" android:layout_weight="1" android:ems="10"
android:inputType="textPersonName" /> Code Java: package edu.huflit.ex2; import ;
android.support.v7.app.AppCompatActivity import android.os.Bundle; import android.view.View; import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText edtTen, edtCanNang, edtChieuCao; Button btnKetQua, btnXoa; TextView tvBMI, tvChuanDoan; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtTen = findViewById(R.id.edtTen);
edtCanNang = findViewById(R.id.edtCanNang);
edtChieuCao = findViewById(R.id.edtChieuCao);
btnKetQua = findViewById(R.id.btnKetQua);
tvBMI = findViewById(R.id.tvBMI);
tvChuanDoan = findViewById(R.id.tvChuanDoan);
btnXoa = findViewById(R.id.btnXoa); btnKetQua new .setOnClickListener( View.OnClickListener() { @Override public void onClick(View v) { double cannang =
Double.parseDouble(edtCanNang.getText().toString()); double chieucao =
Double.parseDouble(edtChieuCao.getText().toString()); ;
Double BMI = cannang / (chieucao * chieucao)
// Xử lý BMI để làm tròn nó
BMI = (double) Math.round(BMI*100)/100;
tvBMI.setText(tvBMI.getText()+ BMI.toString()); //Xử lý thông số BMI
if(BMI < 18) tvChuanDoan.setText("Người gấy");
else if (BMI <= 24.9 && BMI >= 18) tvChuanDoan.setText("Người bình thường");
else if (BMI <= 29.9 && BMI >= 25) tvChuanDoan.setText("Người béo phì độ I");
else if (BMI <= 34.9 && BMI >= 30) tvChuanDoan.setText("Người béo phì cấp độ II");
else if (BMI > 35) tvChuanDoan.setText("Người béo phì cấp độ III"); } });
btnXoa.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { edtCanNang.setText(""); edtChieuCao.setText(""); tvBMI.setText(""); tvChuanDoan.setText(""); } }); } } Bài 3 : ListView Code XML:
<?xml version="1.0" encoding ?> ="utf-8"
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 ="vertical" :orientation tools =".MainActivity" :context android:padding="5dp"> android:id="@+id/lvDiaDanh"
android:layout_width="match_parent"
android:layout_height="256dp" /> android:id="@+id/img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:srcCompat="@tools:sample/avatars" />
android:id="@+id/edtTenDiaDanh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:ems="10"
android:hint="nhập tên địa danh"
android:inputType="textPersonName" />
android:layout_width="match_parent" android:layout_height="44dp"
android:orientation="horizontal"> android:id="@+id/btnThemAnh"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1" android:text="Ảnh..." /> android:id="@+id/btnThem"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1" android:text="Thêm" /> Code Java: package edu.huflit.ex3; import ;
androidx.appcompat.app.AppCompatActivity import android.os.Bundle; import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton; import ; android.widget.ImageView
import android.widget.ListView; import android.widget.Toast; import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
Button btnThemAnh, btnThemDiaDanh; EditText edtTenDiaDanh; ImageView img; ListView ; listView ArrayList arrayList; ArrayAdapter ; arrayAdapter