1.今日收获内容
写了java对应登录的部分,在这里和数据库连接,进行比较
package com.example.myapplication2; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.EditText; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; public class Firstactivity extends AppCompatActivity implements View.OnClickListener{ private EditText editText21; private DatabaseHelper2 dbHelper; private int p=1; String k=""; String xuehao=""; String phone=""; String cla=""; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_first); editText21 = (EditText) findViewById(R.id.edit_21); initUI3(); } private void initUI3() { findViewById(R.id.button1).setOnClickListener(this); findViewById(R.id.button2).setOnClickListener(this); findViewById(R.id.button).setOnClickListener(this); } public void onClick(View v) { switch (v.getId()) { case R.id.button1://执行按钮1 String mm=editText21.getText().toString(); dbHelper=new DatabaseHelper2(this,"TTList2.db",null,3); SQLiteDatabase db=dbHelper.getWritableDatabase(); Cursor cursor=db.query("TTList2",null,null,null, null,null,null);//读取数据库里面专业是软件工程的所有信息 if(cursor.moveToFirst()){ do{ String ye=cursor.getString(cursor.getColumnIndex("手机号")); Log.d("Firstactivity","手机号:"+ye); Log.d("Firstactivity","手机号:"+mm); if(ye.equals(mm)) { k=cursor.getString(cursor.getColumnIndex("姓名")); xuehao=cursor.getString(cursor.getColumnIndex("学号")); phone=cursor.getString(cursor.getColumnIndex("手机号")); cla=cursor.getString(cursor.getColumnIndex("班级")); p=2; } }while (cursor.moveToNext()); } cursor.close(); if(p==2) { Intent intent = new Intent(); intent.putExtra("name",k); intent.putExtra("xuehao",xuehao); intent.putExtra("phone",phone); intent.putExtra("cla",cla); intent.setClass(getApplicationContext(), MainActivity.class); this.startActivity(intent); p=1; } else { Toast.makeText(Firstactivity.this, "无该用户信息", Toast.LENGTH_SHORT).show(); } break; case R.id.button2: Intent intent2 = new Intent(); intent2.setClass(getApplicationContext(), zhuce.class); this.startActivity(intent2); break; case R.id.button: Intent intent3 = new Intent(); intent3.setClass(getApplicationContext(), chakan.class); this.startActivity(intent3); break; } } }
2.遇到的问题
连接失败没有进去
3.明天目标
登录与注册完善