首页 > 其他分享 >打卡18

打卡18

时间:2024-06-19 17:24:32浏览次数:14  
标签:records 18 record sharedPreferences new import 打卡 android

所花时间(包括上课):

 2h

代码量(行):

 150左右

搏客量(篇):

 1

了解到的知识点:

安卓

备注(其他):

 
package com.example.app_02;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class AnalyseActivity extends AppCompatActivity implements View.OnClickListener {

private EditText edAnalyse;

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_analyse);
edAnalyse = findViewById(R.id.edAnalyse);
findViewById(R.id.btn_save).setOnClickListener(this);
}

@Override
public void onClick(View v) {
SharedPreferences sharedPreferences = getSharedPreferences("analyse", Context.MODE_PRIVATE);
@SuppressLint("CommitPrefEdits") SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("analyse",edAnalyse.getText().toString());
editor.apply();
Intent intent = new Intent(this,FirstPageActivity.class);
startActivity(intent);
}
}
package com.example.app_02;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.widget.TextView;

import com.example.app_02.entity.Record;
import com.example.app_02.utils.RecordDao;

import java.util.ArrayList;

public class FirstPageActivity extends AppCompatActivity implements View.OnClickListener {


private String record;
private TextView tvRecord;

private SharedPreferences sharedPreferences;

@SuppressLint({"MissingInflatedId", "SetTextI18n"})
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first_page);

findViewById(R.id.btnGoal).setOnClickListener(this);
findViewById(R.id.btnRecord).setOnClickListener(this);
findViewById(R.id.btnAnalyse).setOnClickListener(this);

TextView tvGoal = findViewById(R.id.tvGoal);
tvRecord = findViewById(R.id.tvRecord);

sharedPreferences = getSharedPreferences("goal", Context.MODE_PRIVATE);
String goalDate = sharedPreferences.getString("goalDate", "");
String goal = sharedPreferences.getString("goal", "");

tvGoal.setText(goalDate + " : " + goal);

sharedPreferences = getSharedPreferences("record", Context.MODE_PRIVATE);
tvRecord.setText(sharedPreferences.getString("record", ""));
//
// h = new Handler(){
// @SuppressLint("HandlerLeak")
// @Override
// public void handleMessage(){
// record = "";
// ArrayList<Record> records = new ArrayList<>();
// RecordDao recordDao = new RecordDao();
// records = recordDao.findRecord();
// for (int i = 0; i < records.size(); i++) {
// record += records.get(i).toString();
// }
// tvRecord.setText(record);
// }
// };


// Handler handler = new Handler(Looper.getMainLooper());
// handler.post(new Runnable() {
// @Override
// public void run() {
// record = "";
// ArrayList<Record> records = new ArrayList<>();
// RecordDao recordDao = new RecordDao();
// records = recordDao.findRecord();
// for (int i = 0; i < records.size(); i++) {
// record += records.get(i).toString();
// }
// tvRecord.setText(record);
// }
// });

//
// FirstPageActivity.this.runOnUiThread(new Runnable() {
// @Override
// public void run() {
// record = "";
// ArrayList<Record> records = new ArrayList<>();
// RecordDao recordDao = new RecordDao();
// records = recordDao.findRecord();
// for (int i = 0; i < records.size(); i++) {
// record += records.get(i).toString();
// }
// tvRecord.setText(record);
// }
// });

}

protected void onResume() {

super.onResume();


sharedPreferences = getSharedPreferences("record", Context.MODE_PRIVATE);
tvRecord.setText(sharedPreferences.getString("record", ""));

// new Thread(new Runnable() {
// @Override
// public void run() {
// record = "";
// ArrayList<Record> records = new ArrayList<>();
// RecordDao recordDao = new RecordDao();
// records = recordDao.findRecord();
// for (int i = 0; i < records.size(); i++) {
// record += records.get(i).toString();
// }
// tvRecord.setText(record);
// }
// }).start();


TextView tvAnalyse = findViewById(R.id.tvAnalyse);
SharedPreferences sharedPreferences = getSharedPreferences("analyse", MODE_PRIVATE);
tvAnalyse.setText(sharedPreferences.getString("analyse", ""));
}

// public void findAll() {
// new Thread(new Runnable() {
// @Override
// public void run() {
// record = "";
// ArrayList<Record> records = new ArrayList<>();
// RecordDao recordDao = new RecordDao();
// records = recordDao.findRecord();
// for (int i = 0; i < records.size(); i++) {
// record += records.get(i).toString();
// }
// }
// }).start();
// }

@Override
public void onClick(View v) {
int i = v.getId();
if (i == R.id.btnGoal) {
Intent intent = new Intent(this, GoalActivity.class);
startActivity(intent);
} else if (i == R.id.btnRecord) {
Intent intent = new Intent(this, RecordActivity.class);
startActivity(intent);
} else {
Intent intent = new Intent(this, AnalyseActivity.class);
startActivity(intent);
}
}
}

标签:records,18,record,sharedPreferences,new,import,打卡,android
From: https://www.cnblogs.com/pinganxile/p/18256697

相关文章

  • 打卡20
    所花时间(包括上课): 2h代码量(行): 150左右搏客量(篇): 1了解到的知识点:安卓备注(其他): packagecom.example.app_02;importandroid.annotation.SuppressLint;importandroid.content.Context;importandroid.content.DialogInterface;impo......
  • 打卡19
    所花时间(包括上课): 2h代码量(行): 150左右搏客量(篇): 1了解到的知识点:安卓备注(其他): packagecom.example.app_02;importandroid.annotation.SuppressLint;importandroid.app.DatePickerDialog;importandroid.content.Context;import......
  • 打卡11
    所花时间(包括上课): 2h代码量(行): 100左右搏客量(篇): 1了解到的知识点: mybits备注(其他):  packagecom.leap.jixianceshiboot.service.impl;importcom.github.pagehelper.Page;importcom.github.pagehelper.PageHelper;importcom.le......
  • 打卡12
    所花时间(包括上课): 2h代码量(行): 150左右搏客量(篇): 1了解到的知识点:springboot备注(其他): packagecom.leap.jixianceshiboot.controller;importcom.leap.jixianceshiboot.entity.Policy;importcom.leap.jixianceshiboot.entity.Poli......
  • 打卡13
    所花时间(包括上课): 2h代码量(行): 100左右搏客量(篇): 1了解到的知识点:vue备注(其他): <scriptsetup>import{ref}from'vue'import{getPolicyService}from"@/api/getPolicy.js";import{ElMessage}from"element-plus&quo......
  • 6.18
    React官方之所以做出这样的更改(在前面提到的PR中已写明),主要是因为在真正暂停渲染之前尝试渲染所有兄弟组件并不是无成本的,这实际上会延迟显示备用内容。此外,这一变化与React团队自React18之前引入Suspense以来一直在推动的“边渲边获取”方法密切相关。理想情况下,我们......
  • docker(ubuntu18.04) + 宿主机(ubuntu20.04) + ROS + 乐视三合一体感摄像头LeTMC-520
    参考链接:https://blog.csdn.net/weixin_45225720/article/details/1144642441.准备docker环境dockerpullhyeonjaegil/vins-monodockerrun-it--privileged--networkhost--gpusall\-v/tmp/.X11-unix:/tmp/.X11-unix\-eDISPLAY-eNVIDIA_VISIBLE_DEVIC......
  • 代码随想录算法训练营第四十三天 | 完全背包理论基础、518.零钱兑换II、377. 组合总和
    完全背包理论基础题目链接:https://kamacoder.com/problempage.php?pid=1052文档讲解:https://programmercarl.com/%E8%83%8C%E5%8C%85%E9%97%AE%E9%A2%98%E7%90%86%E8%AE%BA%E5%9F…视频讲解:https://www.bilibili.com/video/BV1uK411o7c9/思路完全背包中,每个物品可以......
  • 打卡信奥刷题(112)用Scratch图形化工具信奥P6181 [普及组][USACO10OPEN] Mountain Watch
    [USACO10OPEN]MountainWatchingS题目描述一天,Bessie望着远处的山脉,在思考:“哪一座山最宽呢?”Bessie设法测量了NNN个位置的高度......
  • IT66352: 2 IN to 1 OUT HDMI2.0 18Gb/s Re Timer Switch
    TheIT66352isaHDMI2.02INto1OUTre-timerswitchwhichsupportsmaximumsignalingrateupto6Gbps/channel. IT66352是一款HDMI2.02INto1OUT重定时器开关,支持最高6Gbps/通道的信令速率。ItiscomplianttothelatestHDMI2.0bspecification4Kx2K@50/6......