安卓开发日记57

所学时间:2小时

代码行数:110

博客园数:1篇

所学知识:继续代码的完成

package com.example.myexamproject;



import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.myexamproject.R;
import com.example.myexamproject.UpdateIFActivity;
import com.example.myexamproject.bean.Student;
import com.example.myexamproject.utils.StudentDbHelper;

import java.util.LinkedList;


/**
* 我的个人信息活动类
*/
public class MyIFActivity extends AppCompatActivity {

TextView tvStuName,tvStuMajor,tvStuPhone,tvStuQq,tvStuAddress;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_ifactivity);
Button btnBack = findViewById(R.id.btn_back);
//返回点击事件,销毁当前界面
btnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
//从bundle中获取用户账号/学号
final TextView tvUserNumber = findViewById(R.id.tv_stu_number);
tvUserNumber.setText(this.getIntent().getStringExtra("stu_number1"));
tvStuName = findViewById(R.id.tv_stu_name);
tvStuMajor = findViewById(R.id.tv_stu_major);
tvStuPhone = findViewById(R.id.tv_stu_phone);
tvStuQq = findViewById(R.id.tv_stu_qq);
tvStuAddress = findViewById(R.id.tv_stu_address);
StudentDbHelper dbHelper = new StudentDbHelper(getApplicationContext(),StudentDbHelper.DB_NAME,null,1);
LinkedList<Student> students = dbHelper.readStudents(tvUserNumber.getText().toString());
if(students != null) {
for(Student student : students) {
tvStuName.setText(student.getStuName());
tvStuMajor.setText(student.getStuMajor());
tvStuPhone.setText(student.getStuPhone());
tvStuQq.setText(student.getStuQq());
tvStuAddress.setText(student.getStuAddress());
}
}else {
tvStuName.setText("暂未填写");
tvStuMajor.setText("暂未填写");
tvStuPhone.setText("暂未填写");
tvStuQq.setText("暂未填写");
tvStuAddress.setText("暂未填写");
}
Button btnModifyInfo = findViewById(R.id.btn_modify_info);
//跳转到修改用户信息界面
btnModifyInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), UpdateIFActivity.class);
Bundle bundle = new Bundle();
bundle.putString("stu_number2",tvUserNumber.getText().toString());
intent.putExtras(bundle);
startActivity(intent);
}
});

}
}
posted @ 2024-06-14 18:26  大虚胖子  阅读(1)  评论(0编辑  收藏  举报