Bài 1 package com example quanan1; public class Quanan { private String ten Quanan=; private String diachi Quanan=; public String getTen Quanan() { return ten Quanan; } public void setTen Quanan(String ten Quanan) { this ten Quanan = ten Quanan; } public String getDiachi Quanan() { return diachi Quanan; } public void setDiachi Quanan(String diachi Quanan) { this diachi Quanan = diachi Quanan; } } package com example quanan1; import android support v7 app AppCompatActivity; import android os.
Bài package com.example.quanan1; public class Quanan { private String ten_Quanan=""; private String diachi_Quanan=""; public String getTen_Quanan() { return ten_Quanan; } public void setTen_Quanan(String ten_Quanan) { this.ten_Quanan = ten_Quanan; } public String getDiachi_Quanan() { return diachi_Quanan; } public void setDiachi_Quanan(String diachi_Quanan) { this.diachi_Quanan = diachi_Quanan; } } package com.example.quanan1; import import import import import android.support.v7.app.AppCompatActivity; android.os.Bundle; android.view.View; android.widget.Button; android.widget.EditText; public class MainActivity extends AppCompatActivity { Quanan quanan=new Quanan(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn=findViewById(R.id.button_luu); btn.setOnClickListener(on_Luu); } private View.OnClickListener on_Luu=new View.OnClickListener() { @Override public void onClick(View view) { EditText edt_ten=findViewById(R.id.editTextTextPersonName); EditText edt_diachi=findViewById(R.id.editTextTextPersonName2); quanan.setTen_Quanan(edt_ten.getText().toString()); quanan.setDiachi_Quanan((edt_diachi.getText().toString())); } }; } Bài Bài package com.example.quanan1; public class Quanan { private String ten_Quanan=""; private String diachi_Quanan=""; private String kieu_Quanan=""; public String getTen_Quanan() { return ten_Quanan; } public void setTen_Quanan(String ten_Quanan) { this.ten_Quanan = ten_Quanan; } public String getDiachi_Quanan() { return diachi_Quanan; } public String getKieu_Quanan() { return kieu_Quanan; } public void setKieu_Quanan(String kieu_Quanan) { this.kieu_Quanan = kieu_Quanan; } public void setDiachi_Quanan(String diachi_Quanan) { this.diachi_Quanan = diachi_Quanan; } public String toString(){ return (getTen_Quanan()); } } package com.example.quanan1; import import import import import import import import import import import import import import import android.content.Context; android.support.annotation.NonNull; android.support.annotation.Nullable; android.support.v7.app.AppCompatActivity; android.os.Bundle; android.view.LayoutInflater; android.view.View; android.view.ViewGroup; android.widget.ArrayAdapter; android.widget.Button; android.widget.EditText; android.widget.ImageView; android.widget.ListView; android.widget.RadioGroup; android.widget.TextView; import java.util.ArrayList; import java.util.List; import java.util.Random; public class MainActivity extends AppCompatActivity { List model=new ArrayList(); QuananAdapter quananAdapter=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn=findViewById(R.id.btn_luu); btn.setOnClickListener(on_Luu); ListView listView=findViewById(R.id.list_item); quananAdapter=new QuananAdapter(); listView.setAdapter(quananAdapter); } private View.OnClickListener on_Luu=new View.OnClickListener() { @Override public void onClick(View view) { Quanan quanan=new Quanan(); EditText edt_ten=findViewById(R.id.editTextTextPersonName_ten); EditText edt_diachi=findViewById(R.id.editTextTextPersonName_diachi); RadioGroup r=findViewById(R.id.radioGroup_kieu); quanan.setTen_Quanan(edt_ten.getText().toString()); quanan.setDiachi_Quanan(edt_diachi.getText().toString()); switch (r.getCheckedRadioButtonId()){ case R.id.radioButton_ansang: quanan.setKieu_Quanan("Ăn sáng"); break; case R.id.radioButton_antrua: quanan.setKieu_Quanan("Ăn trưa"); break; case R.id.radioButton_VIP: quanan.setKieu_Quanan("VIP"); break; } quananAdapter.add(quanan); } }; class QuananAdapter extends ArrayAdapter{ QuananAdapter(){ super(MainActivity.this,R.layout.row,model); } @NonNull @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { View row=convertView; QuananHolder quananHolder=null; if(row==null){ LayoutInflater inflater=getLayoutInflater(); row=inflater.inflate(R.layout.row,parent,false); quananHolder=new QuananHolder(row); row.setTag(quananHolder); } else{ quananHolder=(QuananHolder)row.getTag(); } quananHolder.dien_dong(model.get(position)); return row; } } static class QuananHolder{ private TextView ten=null; private TextView diachi=null; private ImageView icon=null; QuananHolder(View row){ ten=row.findViewById(R.id.textView_ten); diachi=row.findViewById(R.id.textView_diachi); icon=row.findViewById(R.id.imageView_kieu); } void dien_dong(Quanan quanan){ ten.setText(quanan.getTen_Quanan()); diachi.setText(quanan.getDiachi_Quanan()); if(quanan.getKieu_Quanan().equals("Ăn sáng")){ icon.setImageResource(R.drawable.an_sang); }else if (quanan.getKieu_Quanan().equals("Ăn trưa")){ icon.setImageResource(R.drawable.an_trua); } else {icon.setImageResource(R.drawable.vip);} } } }