每日总结2023/3/5

今天进行了每日打卡app的本地登录注册连接测试,同时进行了关键字自己学习内容的添加完成

下面是实现修改密码

package com.example.a86191.timeword;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.view.View;

public class update extends AppCompatActivity {

    private EditText name,password,repassword;
    private Button update;
    private MYsqLiteopenhelper mYsqliteopenhelper2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_update);
        mYsqliteopenhelper2 =new MYsqLiteopenhelper(this);
        find();
    }

    private void find() {
        name =findViewById(R.id.etname2);
        password =findViewById(R.id.edpassword2);
        repassword =findViewById(R.id.repassword1);
    }
    public void xiugai(View view) {
        String s = name.getText().toString();
        String s1 = password.getText().toString();
        String s2 = repassword.getText().toString();
        int update = mYsqliteopenhelper2.update(s, s2, s1);
        if (update !=-1){
            Toast.makeText(this, "密码修改成功!", Toast.LENGTH_SHORT).show();
            Intent i1=new Intent(this,MainActivity.class);
            startActivity(i1);
        }else {
            Toast.makeText(this, "密码修改失败!", Toast.LENGTH_SHORT).show();
        }
    }
}
 public int update(String name,String NEWpassword,String password){
        SQLiteDatabase db2 = getWritableDatabase();
        ContentValues cv1=new ContentValues();
        boolean login = login(name, password);
        if (login){
            cv1.put("name",name);
            cv1.put("password",NEWpassword);
        }else {
            int o=-1;
            return o;
        }

        int i = db2.update("users", cv1, "name= ?", new String[]{name});
        return i;

    }

openhelpr内容

<?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"
    tools:context=".update"
    android:orientation="vertical"
    >
    <View
        android:layout_width="match_parent"
        android:layout_height="120dp"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="账号:"
            android:layout_weight="1"
            android:textSize="30dp"
            android:gravity="center_vertical"/>
        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:id="@+id/etname2"/>


    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="原密码:"
            android:layout_weight="1"
            android:textSize="25dp"
            android:gravity="center_vertical"/>
        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:id="@+id/edpassword2"/>



    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="密码改为:"
            android:layout_weight="1"
            android:textSize="20dp"
            android:gravity="center_vertical"/>
        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:id="@+id/repassword1"/>



    </LinearLayout>
    <Button
        android:layout_width="160dp"
        android:layout_height="80dp"
        android:text="修改"
        android:textSize="27dp"
        android:id="@+id/update1"
        android:layout_gravity="center"
        android:onClick="xiugai"
        />
</LinearLayout>

 

posted @ 2023-03-05 18:36  橘子味芬达水  阅读(12)  评论(0编辑  收藏  举报