第四天 | |
所花时间(包括上课) | 2h |
代码量(行) | 130行 |
博客量(篇) | 2篇 |
了解到的知识点 | 无多少新的知识点,主要是对前三天的内容进行复习,并且进行编写。 |
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_record); // 1、查找控件 tabLayout = findViewById(R.id.record_tabs); viewPager = findViewById(R.id.record_vp); // 2、设置ViewPaper加载页面 initPager(); } private void initPager() { // 初始化(fragment) ViewPaper的集合 List<Fragment> fragmentList = new ArrayList<>(); // 创建收入和支出页面,放在fragment当中 OutFragment outFragment= new OutFragment(); InFragment inFragment = new InFragment(); fragmentList.add(outFragment); fragmentList.add(inFragment); //创建适配器 RecordPagerAdapter recordPagerAdapter = new RecordPagerAdapter(getSupportFragmentManager(), fragmentList); //设置适配器对象 viewPager.setAdapter(recordPagerAdapter); //将TabLayout和ViewPaper进行关联 tabLayout.setupWithViewPager(viewPager); } public void onClick(View view) { if (view.getId() == R.id.record_iv_back) { finish(); } } }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initTime(); extracted(); preferences = getSharedPreferences("budget", Context.MODE_PRIVATE); addLVHeaderView(); mDatas = new ArrayList<>(); //设置适配器:加载每一行数据到列表当中 adapter = new AccountAdapter(this, mDatas); todayLv.setAdapter(adapter); } private void extracted() { todayLv = findViewById(R.id.main_lv); editBtn = findViewById(R.id.main_btn_edit); moreBtn = findViewById(R.id.main_btn_more); searchIv = findViewById(R.id.main_iv_search); editBtn.setOnClickListener(this); moreBtn.setOnClickListener(this); searchIv.setOnClickListener(this); } private void addLVHeaderView() { headerView = getLayoutInflater().inflate(R.layout.item_mainlv_top, null); todayLv.addHeaderView(headerView); topOutTv = headerView.findViewById(R.id.item_mainlv_top_tv_out); topInTv = headerView.findViewById(R.id.item_mainlv_top_tv_in); topbudgetTv = headerView.findViewById(R.id.item_mainlv_top_tv_budget); topConTv = headerView.findViewById(R.id.item_mainlv_top_tv_day); topShowIv = headerView.findViewById(R.id.item_mainlv_top_iv_hide); topbudgetTv.setOnClickListener(this); headerView.setOnClickListener(this); topShowIv.setOnClickListener(this); } private void initTime() { Calendar calendar = Calendar.getInstance(); year = calendar.get(Calendar.YEAR); month = calendar.get(Calendar.MONTH) + 1; day = calendar.get(Calendar.DAY_OF_MONTH); } //当activity获取焦点时,会调用的方法 @Override protected void onResume() { super.onResume(); loadDBData(); setTopTvShow(); } private void setTopTvShow() { float outMonthCome = DBManager.getMoneyOneMonth(year, month, 0); float inMonthCome = DBManager.getMoneyOneMonth(year, month, 1); float outDayCome = DBManager.getMoneyOneDay(year, month, day, 0); float inDayCome = DBManager.getMoneyOneDay(year, month, day, 1); String infoOneDay = "今日支出 ¥" + outDayCome + " ,收入 ¥" + inDayCome; topConTv.setText(infoOneDay); topInTv.setText("¥ " + inMonthCome); topOutTv.setText("¥ " + outMonthCome); //设置预算剩余 float bMoney = preferences.getFloat("bmoney", 0); if (bMoney == 0) { topbudgetTv.setText(" ¥0"); } else { float bMoney1 = bMoney - outMonthCome; topbudgetTv.setText(" ¥" + bMoney1); } }
标签:headerView,mainlv,2024.03,08,findViewById,id,item,void From: https://www.cnblogs.com/dmx-03/p/18061380