Guest User

Untitled

a guest
Sep 30th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.23 KB | None | 0 0
  1. package com.example.lenovo.android;
  2.  
  3. import android.content.DialogInterface;
  4. import android.support.annotation.NonNull;
  5. import android.support.design.widget.NavigationView;
  6. import android.support.v4.app.Fragment;
  7. import android.support.v4.app.FragmentManager;
  8. import android.support.v4.view.GravityCompat;
  9. import android.support.v4.widget.DrawerLayout;
  10. import android.support.v7.app.ActionBar;
  11. import android.support.v7.app.AlertDialog;
  12. import android.support.v7.app.AppCompatActivity;
  13. import android.os.Bundle;
  14. import android.support.v7.widget.Toolbar;
  15. import android.view.MenuItem;
  16. import android.widget.ListView;
  17. import android.widget.Toast;
  18.  
  19. import com.example.lenovo.android.Adapter.KhoangChiAdapter;
  20. import com.example.lenovo.android.Adapter.KhoangThuAdapter;
  21. import com.example.lenovo.android.Adapter.LoaiChiAdapter;
  22. import com.example.lenovo.android.Adapter.LoaiThuAdapter;
  23. import com.example.lenovo.android.modal.KhoangChi;
  24. import com.example.lenovo.android.modal.KhoangThu;
  25. import com.example.lenovo.android.modal.LoaiChi;
  26. import com.example.lenovo.android.modal.LoaiThu;
  27. import com.example.lenovo.android.sqlite.quanlyDAO;
  28.  
  29. import java.util.ArrayList;
  30.  
  31. public class MainActivity extends AppCompatActivity {
  32.  
  33. DrawerLayout drawer;
  34. Toolbar toolbar;
  35. NavigationView navigation;
  36. ArrayList<LoaiThu> listloaithu = new ArrayList<LoaiThu>();
  37. ArrayList<KhoangThu> listkhoangthu = new ArrayList<KhoangThu>();
  38. ArrayList<LoaiChi> listloaichi = new ArrayList<LoaiChi>();
  39. ArrayList<KhoangChi> listkhoangchi = new ArrayList<KhoangChi>();
  40.  
  41. ListView loaithu,khoangthu,loaichi,khoagchi;
  42. quanlyDAO quanly;
  43. @Override
  44. protected void onCreate(Bundle savedInstanceState) {
  45. super.onCreate(savedInstanceState);
  46. setContentView(R.layout.activity_main);
  47. drawer=(DrawerLayout)findViewById(R.id.drawer_layout);
  48. toolbar=(Toolbar)findViewById(R.id.toolbar);
  49. navigation=(NavigationView)findViewById(R.id.nvView);
  50. loaithu = findViewById(R.id.listviewloaithu);
  51. khoangthu = findViewById(R.id.listviewkhoangthu);
  52. quanly = new quanlyDAO(this);
  53. //set toolbar thay the cho actionbar
  54. setSupportActionBar(toolbar);
  55.  
  56. ActionBar ab=getSupportActionBar();
  57. ab.setHomeAsUpIndicator(R.drawable.ic_menu);
  58. ab.setDisplayHomeAsUpEnabled(true);
  59.  
  60. navigation.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
  61. @Override
  62. public boolean onNavigationItemSelected(@NonNull MenuItem item) {
  63. xulychonmenu(item);
  64.  
  65. return false;
  66. }
  67. });
  68.  
  69. }
  70.  
  71. @Override
  72. public boolean onOptionsItemSelected(MenuItem item) {
  73. if(item.getItemId()==android.R.id.home)
  74. {
  75. drawer.openDrawer(GravityCompat.START);
  76. }
  77. return super.onOptionsItemSelected(item);
  78. }
  79.  
  80. public void xulychonmenu(MenuItem item)
  81. {
  82. Fragment fragment=null;
  83. Class classfragment=null;
  84. if(item.getItemId()==R.id.thufragment);
  85. Toast.makeText(this, "ddd", Toast.LENGTH_SHORT).show(); if(item.getItemId()==R.id.chifragment)
  86. classfragment=ChiFragment.class;
  87. if(item.getItemId()==R.id.thongke)
  88. classfragment=ThongkeFragment.class;
  89. if(item.getItemId()==R.id.about)
  90. classfragment=AboutFragment.class;
  91. if(item.getItemId()==R.id.exit)
  92. showAlertDialog();
  93. //....tao cac fragment cho tung muc
  94.  
  95. /*try {
  96. fragment=(Fragment)classfragment.newInstance();
  97.  
  98. FragmentManager fmanager= getSupportFragmentManager();
  99. fmanager.beginTransaction()
  100. .replace(R.id.flContent,fragment)
  101. .commit();
  102.  
  103. item.setChecked(true);
  104. setTitle(item.getTitle());
  105. drawer.closeDrawer(GravityCompat.START);
  106. }catch(Exception e) {*/
  107.  
  108. }
  109.  
  110. /*
  111. public void updateLoaiThu(){
  112. quanly = new quanlyDAO(MainActivity.this);
  113. loaithu = findViewById(R.id.listviewloaithu);
  114. listloaithu = quanly.xemLoaiThu();
  115. LoaiThuAdapter adapterLoai = new LoaiThuAdapter(listloaithu,MainActivity.this);
  116. loaithu.setAdapter(adapterLoai);
  117. }*/
  118.  
  119. public void updateLoaiChi(){
  120. quanly = new quanlyDAO(MainActivity.this);
  121. loaichi = findViewById(R.id.listviewloaichi);
  122. listloaichi = quanly.xemLoaiChi();
  123. LoaiChiAdapter adapterLoai = new LoaiChiAdapter(listloaichi,MainActivity.this);
  124. loaichi.setAdapter(adapterLoai);
  125. }
  126.  
  127.  
  128. public void updateKhoangThu(){
  129. quanly = new quanlyDAO(MainActivity.this);
  130. khoangthu = findViewById(R.id.listviewkhoangthu);
  131. listkhoangthu = quanly.xemKhoangThu();
  132. KhoangThuAdapter adapterKhoangThu = new KhoangThuAdapter(listkhoangthu,MainActivity.this);
  133. khoangthu.setAdapter(adapterKhoangThu);
  134. }
  135.  
  136. public void updateKhoangChi(){
  137. quanly = new quanlyDAO(MainActivity.this);
  138. khoagchi = findViewById(R.id.listviewkhoangchi);
  139. listkhoangchi = quanly.xemKhoangChi();
  140. KhoangChiAdapter adapterKhoangChi = new KhoangChiAdapter(listkhoangchi,MainActivity.this);
  141. khoagchi.setAdapter(adapterKhoangChi);
  142. }
  143.  
  144. public void showAlertDialog(){
  145. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  146. builder.setTitle("Tạm biệt !");
  147. builder.setMessage("Bạn có muốn đăng xuất không?");
  148. builder.setCancelable(false);
  149. builder.setPositiveButton("Không!", new DialogInterface.OnClickListener() {
  150. @Override
  151. public void onClick(DialogInterface dialogInterface, int i) {
  152. Toast.makeText(MainActivity.this, "Ok", Toast.LENGTH_SHORT).show();
  153. }
  154. });
  155. builder.setNegativeButton("Đăng xuất", new DialogInterface.OnClickListener() {
  156. @Override
  157. public void onClick(DialogInterface dialogInterface, int i) {
  158. dialogInterface.dismiss();
  159. System.exit(0);
  160. }
  161. });
  162. AlertDialog alertDialog = builder.create();
  163. alertDialog.show();
  164.  
  165. }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment