欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

AndriodStudio利用ListView和數(shù)據(jù)庫(kù)實(shí)現(xiàn)簡(jiǎn)單學(xué)生管理

 更新時(shí)間:2022年03月29日 08:43:23   作者:修24352  
這篇文章主要為大家詳細(xì)介紹了AndriodStudio利用ListView和數(shù)據(jù)庫(kù)實(shí)現(xiàn)簡(jiǎn)單學(xué)生管理,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了AndriodStudio利用ListView和數(shù)據(jù)庫(kù)實(shí)現(xiàn)簡(jiǎn)單學(xué)生管理的具體代碼,供大家參考,具體內(nèi)容如下

數(shù)據(jù)庫(kù)的創(chuàng)建

package com.example.myapp;
?
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;
?
public class DbHelper extends SQLiteOpenHelper {
? ? final String create_table="CREATE TABLE Student (_id integer primary key autoincrement,xm text,xh text,bj text,zy text,cj text)";
? ? final String create_register="CREATE TABLE Register (_id integer primary key autoincrement,xm text,xh text)";
//創(chuàng)建兩張表,一張student,一張register表
? ? Context context;
? ? public DbHelper(Context context,String dbname,int version){
? ? ? ? super(context,dbname,null,version);
? ? ? ? this.context=context;//上下文
? ? }
? ? @Override
? ? public void onCreate(SQLiteDatabase db) {db.execSQL(create_table); db.execSQL(create_register);}
?
? ? @Override
? ? public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
? ? ? ? db.execSQL("drop table if exists Student");
? ? ? ? db.execSQL("drop table if exists Register");
? ? ? ? db.execSQL(create_table);
? ? ? ? db.execSQL(create_register);
//完成創(chuàng)建
? ? }
// 對(duì)表進(jìn)行數(shù)據(jù)的插入方法
? ? public void insert(String tableName, ContentValues values){
? ? ? ? SQLiteDatabase db = getReadableDatabase();
? ? ? ? db.insert(tableName,null,values);
? ? ? ? Toast.makeText(context,"成功插入數(shù)據(jù)!",Toast.LENGTH_SHORT).show();
? ? }
//查詢表中所有
? ? public Cursor queryAll(String tableName){
? ? ? ? SQLiteDatabase db = getReadableDatabase();
? ? ? ? Cursor cursor = db.query(tableName,null,null,null,null,null,null);
? ? ? ? return cursor;
? ? }
//對(duì)表中的姓名和學(xué)號(hào)進(jìn)行單獨(dú)的查詢
? ? public Boolean queryByStudentXhAndXm(String tableName,String xm,String xh){
? ? ? ? SQLiteDatabase db = getReadableDatabase();
? ? ? ? Cursor cursor = db.query(tableName,new String[]{"xm,xh"},"xm=? and xh=?",new String[]{xm,xh},null,null,null);
? ? ? ? if (cursor.moveToFirst()) {
? ? ? ? ? ? return true;
? ? ? ? }else {
? ? ? ? ? ? return false;
? ? ? ? }
? ? }
//刪除表中數(shù)據(jù)的方法
? ? public void delStudent(String id){
? ? ? ? SQLiteDatabase db = getWritableDatabase();
? ? ? ? db.delete("Student","_id=?",new String[]{id});
? ? }
//對(duì)表進(jìn)行更新
? ? public void ?updateStudent(String id,ContentValues values){
? ? ? ? SQLiteDatabase db = getWritableDatabase();
? ? ? ? db.update("Student",values,"_id=?",new String[]{id});
? ? }
}

創(chuàng)建了兩張表格,一張用來(lái)儲(chǔ)存學(xué)生信息,Student表:id(主鍵),姓名,學(xué)號(hào),班級(jí),專業(yè),成績(jī)。

一張register表:id(主鍵),姓名,學(xué)號(hào)。用來(lái)儲(chǔ)存登錄信息

其余類和其布局文件

MainActivity.class(登錄界面)

package com.example.myapp;
?
import androidx.appcompat.app.AppCompatActivity;
?
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
?
public class MainActivity extends AppCompatActivity {
? ? EditText et1,et2;
? ? Button btn1,btn2;
? ? DbHelper dbHelper;
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? dbHelper=new DbHelper(MainActivity.this,"MyDataBase,",3);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? et1=findViewById(R.id.et1);
? ? ? ? et2=findViewById(R.id.et2);
? ? ? ? btn1=findViewById(R.id.dl);
? ? ? ? btn2=findViewById(R.id.zc);
?
? ? ? ? btn1.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? String xm=et1.getText().toString();
? ? ? ? ? ? ? ? String xh=et2.getText().toString();
? ? ? ? ? ? ? ? if (xm.isEmpty()||xh.isEmpty()){
? ? ? ? ? ? ? ? ? ? Toast.makeText(MainActivity.this,"姓名或者學(xué)號(hào)不可為空",Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (dbHelper.queryByStudentXhAndXm("Register",xm,xh)){
? ? ? ? ? ? ? ? ? ? Intent intent=new Intent(MainActivity.this,Manage.class);
? ? ? ? ? ? ? ? ? ? startActivity(intent);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? btn2.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? Intent intent=new Intent(MainActivity.this,Register.class);
? ? ? ? ? ? ? ? startActivity(intent);
? ? ? ? ? ? }
? ? ? ? });
? ? }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? xmlns:app="http://schemas.android.com/apk/res-auto"
? ? xmlns:tools="http://schemas.android.com/tools"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? android:orientation="vertical"
? ? tools:context=".MainActivity">
?
? ? <EditText
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:id="@+id/et1"
? ? ? ? android:hint="輸入姓名"/>
? ? <EditText
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:id="@+id/et2"
? ? ? ? android:hint="學(xué)號(hào)"/>
? ? <Button
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:id="@+id/dl"
? ? ? ? android:text="登錄"/>
? ? <Button
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="注冊(cè)"
? ? ? ? android:id="@+id/zc"/>
?
</LinearLayout>

Register.class(注冊(cè)界面)

package com.example.myapp;
?
import androidx.appcompat.app.AppCompatActivity;
?
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
?
public class Register extends AppCompatActivity {
? ? EditText et1,et2;
? ? Button btn1,btn2;
? ? DbHelper dbHelper;
? ? TextView show;
?
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_register);
? ? ? ? dbHelper=new DbHelper(Register.this,"MyDataBase,",3);
? ? ? ? et1=findViewById(R.id.xm_zc);
? ? ? ? et2=findViewById(R.id.xh_zc);
? ? ? ? show=findViewById(R.id.tv_show);
? ? ? ? btn1=findViewById(R.id.qd_zc);
? ? ? ? btn2=findViewById(R.id.fh);
?
? ? ? ? btn1.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? String xm=et1.getText().toString();
? ? ? ? ? ? ? ? String xh=et2.getText().toString();
? ? ? ? ? ? ? ? if(TextUtils.isEmpty(xm)||TextUtils.isEmpty(xh)){
? ? ? ? ? ? ? ? ? ? Toast.makeText(Register.this,"姓名或者學(xué)號(hào)不能為空",Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ContentValues values = new ContentValues();
? ? ? ? ? ? ? ? values.put("xm",xm);
? ? ? ? ? ? ? ? values.put("xh",xh);
? ? ? ? ? ? ? ? dbHelper.insert("Register",values);
? ? ? ? ? ? ? ? showUser();
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? btn2.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? Intent intent=new Intent(Register.this,MainActivity.class);
? ? ? ? ? ? ? ? startActivity(intent);
? ? ? ? ? ? }
? ? ? ? });
? ? }
? ? public void showUser(){
? ? ? ? Cursor cursor = dbHelper.queryAll("Register");
? ? ? ? String str = "_id ? ? ? ?xm ? ? ? ? xh\n";
? ? ? ? if (cursor.moveToFirst())
? ? ? ? ? ? while (cursor.moveToNext()){
? ? ? ? ? ? ? ? str += cursor.getString(0)+" ? ? ?";
? ? ? ? ? ? ? ? str += cursor.getString(1)+" ? ? ?";
? ? ? ? ? ? ? ? str += cursor.getString(2)+"\n";
? ? ? ? ? ? };
? ? ? ? show.setText(str);
? ? }
}

activity_register.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? xmlns:app="http://schemas.android.com/apk/res-auto"
? ? xmlns:tools="http://schemas.android.com/tools"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? android:orientation="vertical"
? ? tools:context=".Register">
? ? <EditText
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:id="@+id/xm_zc"
? ? ? ? android:hint="輸入姓名"/>
? ? <EditText
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:id="@+id/xh_zc"
? ? ? ? android:hint="輸入學(xué)號(hào)"/>
? ? <Button
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="確認(rèn)注冊(cè)"
? ? ? ? android:id="@+id/qd_zc"/>
? ? <Button
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="返回上一層"
? ? ? ? android:id="@+id/fh"/>
? ? <TextView
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="match_parent"
? ? ? ? android:id="@+id/tv_show"/>
?
</LinearLayout>

Manage.class(管理界面)

package com.example.myapp;
?
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
?
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
?
public class Manage extends AppCompatActivity {
? ? ListView listView;
? ? Button btn;
? ? DbHelper dbHelper;
?
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_manage);
? ? ? ? AlertDialog.Builder builder = new AlertDialog.Builder(Manage.this);
? ? ? ? dbHelper = new DbHelper(Manage.this,"MyDataBase,",3);
? ? ? ? listView=findViewById(R.id.list);
? ? ? ? dbHelper.getWritableDatabase();
? ? ? ? renderListView();
? ? ? ? btn=findViewById(R.id.new_list);
? ? ? ? btn.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? Intent intent=new Intent(Manage.this,NewStudent.class);
? ? ? ? ? ? ? ? startActivityForResult(intent,1);
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onItemClick(AdapterView<?> parent, View view, int position, long idi) {
? ? ? ? ? ? ? ? Cursor cursor = dbHelper.queryAll("Student");
? ? ? ? ? ? ? ? cursor.move(position+1);
? ? ? ? ? ? ? ? String id = cursor.getString(cursor.getColumnIndex("_id"));
? ? ? ? ? ? ? ? String xm = cursor.getString(cursor.getColumnIndex("xm"));
? ? ? ? ? ? ? ? String xh = cursor.getString(cursor.getColumnIndex("xh"));
? ? ? ? ? ? ? ? String bj = cursor.getString(cursor.getColumnIndex("bj"));
? ? ? ? ? ? ? ? String zy = cursor.getString(cursor.getColumnIndex("zy"));
? ? ? ? ? ? ? ? String cj = cursor.getString(cursor.getColumnIndex("cj"));
? ? ? ? ? ? ? ? Intent intent = new Intent(Manage.this,NewStudent.class);
? ? ? ? ? ? ? ? intent.putExtra("id",id);
? ? ? ? ? ? ? ? intent.putExtra("xm",xm);
? ? ? ? ? ? ? ? intent.putExtra("xh",xh);
? ? ? ? ? ? ? ? intent.putExtra("bj",bj);
? ? ? ? ? ? ? ? intent.putExtra("zy",zy);
? ? ? ? ? ? ? ? intent.putExtra("cj",cj);
? ? ? ? ? ? ? ? startActivityForResult(intent,2);
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long idi) {
? ? ? ? ? ? ? ? Cursor cursor = dbHelper.queryAll("Student");
? ? ? ? ? ? ? ? cursor.move(position+1);
? ? ? ? ? ? ? ? String id = cursor.getString(cursor.getColumnIndex("_id"));//getColumnIndex("_id")得到這一列
? ? ? ? ? ? ? ? String xm = cursor.getString(cursor.getColumnIndex("xm"));
? ? ? ? ? ? ? ? builder.setTitle("刪除確認(rèn)").setMessage("是否確認(rèn)刪除學(xué)生"+xm);
? ? ? ? ? ? ? ? builder.setPositiveButton("確定", new DialogInterface.OnClickListener() {
? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? public void onClick(DialogInterface dialog, int which) {
? ? ? ? ? ? ? ? ? ? ? ? dbHelper.delStudent(id);
? ? ? ? ? ? ? ? ? ? ? ? renderListView();
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? builder.show();
? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? }
? ? ? ? });
? ? }
? ? private void renderListView() {
? ? ? ? Cursor cursor = dbHelper.queryAll("Student");
? ? ? ? String from[] = new String[]{"_id", "xm", "xh","bj","zy","cj"};
? ? ? ? int to[] = new int[]{R.id.id,R.id.xm, R.id.xh, R.id.bj, R.id.zy, R.id.cj};
? ? ? ? SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.listview, cursor, from, to, 0);
? ? ? ? ListView listView = findViewById(R.id.list);
? ? ? ? listView.setAdapter(adapter);
? ? }
? ? @Override
? ? protected ?void onActivityResult(int reqCode,int resultCode,Intent intent){
? ? ? ? super.onActivityResult(reqCode,resultCode,intent);
? ? ? ? if (resultCode==RESULT_OK){
? ? ? ? ? ? String xm = intent.getStringExtra("xm");
? ? ? ? ? ? String xh = intent.getStringExtra("xh");
? ? ? ? ? ? String bj = intent.getStringExtra("bj");
? ? ? ? ? ? String zy = intent.getStringExtra("zy");
? ? ? ? ? ? String cj = intent.getStringExtra("cj");
? ? ? ? ? ? dbHelper.getWritableDatabase();
? ? ? ? ? ? ContentValues values = new ContentValues();
? ? ? ? ? ? values.put("xm",xm);
? ? ? ? ? ? values.put("xh",xh);
? ? ? ? ? ? values.put("bj",bj);
? ? ? ? ? ? values.put("zy",zy);
? ? ? ? ? ? values.put("cj",cj);
? ? ? ? ? ? if (reqCode==1)
? ? ? ? ? ? ? ? dbHelper.insert("Student",values);
? ? ? ? ? ? else if (reqCode==2){
? ? ? ? ? ? ? ? String id = intent.getStringExtra("id");
? ? ? ? ? ? ? ? dbHelper.updateStudent(id,values);
? ? ? ? ? ? }
? ? ? ? ? ? renderListView();
? ? ? ? }
? ? }
}

activity_manage.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? xmlns:app="http://schemas.android.com/apk/res-auto"
? ? xmlns:tools="http://schemas.android.com/tools"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? android:orientation="vertical"
? ? tools:context=".Manage">
?
? ? <ListView
? ? ? ? android:id="@+id/list"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content" />
?
? ? <Button
? ? ? ? android:id="@+id/new_list"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="添加新學(xué)生" />
?
</LinearLayout>

對(duì)應(yīng)的listview的布局文件,listview.xml

因?yàn)槭褂玫氖菙?shù)據(jù)庫(kù)來(lái)儲(chǔ)存信息和調(diào)用,并沒(méi)有重寫對(duì)于listview的Adapter,而是使用Android自帶的SimpleCursorAdapter類方法,用游標(biāo)來(lái)儲(chǔ)存,查看數(shù)據(jù)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? android:orientation="vertical">
? ? <LinearLayout
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:orientation="horizontal">
? ? ? ? <TextView
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="50dp"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:text="id"/>
?
? ? ? ? <TextView
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="50dp"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:text="姓名" />
?
? ? ? ? <TextView
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="50dp"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:text="學(xué)號(hào)" />
?
? ? ? ? <TextView
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="50dp"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:text="班級(jí)" />
?
? ? ? ? <TextView
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="50dp"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:text="專業(yè)" />
?
? ? ? ? <TextView
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="50dp"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:text="成績(jī)" />
?
?
? ? </LinearLayout>
?
? ? <LinearLayout
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:orientation="horizontal">
? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/id"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="50dp"
? ? ? ? ? ? android:layout_weight="1" />
?
? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/xm"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="50dp"
? ? ? ? ? ? android:layout_weight="1" />
?
? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/xh"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="50dp"
? ? ? ? ? ? android:layout_weight="1" />
?
? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/bj"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="50dp"
? ? ? ? ? ? android:layout_weight="1" />
?
? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/zy"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="50dp"
? ? ? ? ? ? android:layout_weight="1" />
?
? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/cj"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="50dp"
? ? ? ? ? ? android:layout_weight="1" />
? ? </LinearLayout>
?
</LinearLayout>

對(duì)于新添加學(xué)生操作,使用NewStudent.class來(lái)完成

package com.example.myapp;
?
import androidx.appcompat.app.AppCompatActivity;
?
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
?
public class NewStudent extends AppCompatActivity {
? ? DbHelper dbHelper;
?
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_new_student);
? ? ? ? dbHelper=new DbHelper(NewStudent.this,"MyDataBase",3);
? ? ? ? Intent priIntent = getIntent();
?
? ? ? ? EditText et_xm = findViewById(R.id.et_xm);
? ? ? ? EditText et_xh = findViewById(R.id.et_xh);
? ? ? ? EditText et_bj = findViewById(R.id.et_bj);
? ? ? ? EditText et_zy = findViewById(R.id.et_zy);
? ? ? ? EditText et_cj = findViewById(R.id.et_cj);
? ? ? ? String priId = priIntent.getStringExtra("id");
? ? ? ? String prixm = priIntent.getStringExtra("xm");
? ? ? ? String prixh = priIntent.getStringExtra("xh");
? ? ? ? String pribj = priIntent.getStringExtra("bj");
? ? ? ? String prizy = priIntent.getStringExtra("zy");
? ? ? ? String pricj = priIntent.getStringExtra("cj");
? ? ? ? et_xm.setText(prixm);
? ? ? ? et_xh.setText(prixh);
? ? ? ? et_bj.setText(pribj);
? ? ? ? et_zy.setText(prizy);
? ? ? ? et_cj.setText(pricj);
?
? ? ? ? Button btn_confirm = findViewById(R.id.btn_confirm);
?
? ? ? ? btn_confirm.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? EditText et_xm = findViewById(R.id.et_xm);
? ? ? ? ? ? ? ? EditText et_xh = findViewById(R.id.et_xh);
? ? ? ? ? ? ? ? EditText et_bj = findViewById(R.id.et_bj);
? ? ? ? ? ? ? ? EditText et_zy = findViewById(R.id.et_zy);
? ? ? ? ? ? ? ? EditText et_cj = findViewById(R.id.et_cj);
?
? ? ? ? ? ? ? ? String xm = et_xm.getText().toString();
? ? ? ? ? ? ? ? String xh = et_xh.getText().toString();
? ? ? ? ? ? ? ? String bj = et_bj.getText().toString();
? ? ? ? ? ? ? ? String zy = et_zy.getText().toString();
? ? ? ? ? ? ? ? String cj = et_cj.getText().toString();
? ? ? ? ? ? ? ? if (TextUtils.isEmpty(xm)||TextUtils.isEmpty(xh)){
? ? ? ? ? ? ? ? ? ? Toast.makeText(NewStudent.this,"學(xué)號(hào)或者姓名不可為空",Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? Intent intent = new Intent();
? ? ? ? ? ? ? ? intent.putExtra("_id",priId);
? ? ? ? ? ? ? ? intent.putExtra("xm",xm);
? ? ? ? ? ? ? ? intent.putExtra("xh",xh);
? ? ? ? ? ? ? ? intent.putExtra("bj",bj);
? ? ? ? ? ? ? ? intent.putExtra("zy",zy);
? ? ? ? ? ? ? ? intent.putExtra("cj",cj);
? ? ? ? ? ? ? ? setResult(RESULT_OK,intent);
? ? ? ? ? ? ? ? finish();
? ? ? ? ? ? }
? ? ? ? });
? ? }
}

activity_new_student.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? xmlns:app="http://schemas.android.com/apk/res-auto"
? ? xmlns:tools="http://schemas.android.com/tools"
? ? android:layout_width="match_parent"
? ? android:orientation="vertical"
? ? android:layout_height="match_parent"
? ? tools:context=".NewStudent">
? ? <EditText
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:id="@+id/et_xm"
? ? ? ? android:hint="請(qǐng)輸入姓名"
? ? ? ? />
? ? <EditText
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:id="@+id/et_xh"
? ? ? ? android:hint="請(qǐng)輸入學(xué)號(hào)"
? ? ? ? />
? ? <EditText
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:id="@+id/et_bj"
? ? ? ? android:hint="請(qǐng)輸入班級(jí)"
? ? ? ? />
? ? <EditText
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:id="@+id/et_zy"
? ? ? ? android:hint="請(qǐng)輸入專業(yè)"
? ? ? ? />
? ? <EditText
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:id="@+id/et_cj"
? ? ? ? android:hint="請(qǐng)輸入成績(jī)"
? ? ? ? />
?
? ? <Button
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:id="@+id/btn_confirm"
? ? ? ? android:text="確定"
? ? ? ? />
?
</LinearLayout>

運(yùn)行效果圖:

登錄頁(yè)面:

注冊(cè)界面:

管理界面:

對(duì)listview進(jìn)行操作:?jiǎn)螕?/p>

長(zhǎng)按

對(duì)listview的添加:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論