更新用户信息数据库更新

更新数据库时,如果用户编辑更改了其手机号,那么在查询数据库时其手机号已经更改了,所以这里要再次创建sharedpreference并且提交更改的手机号,这样才能在下次登陆的时候直接登录到更改后新的手机查询的主界面。

这是旧的思想:{但是一旦更改,用户旧的手机号就查询不到数据库列表了,用户的记录listview需要重新键入,是一个属于这个更新的手机号的新的一个record,所以再次登录时将会显示新的。}

新思想为:在更新数据后,直接跳转界面,将新的手机号存储到sharedpreference中提交,这样查询的就是新的手机号的listview了,并且保留了之前的数据库

//更新

    public void click3(View v) {

        SQLiteDatabase db = myOpenHelper.getWritableDatabase();

        ContentValues values = new ContentValues();

        values.put("login_tel", "3new");

        String args1=String.valueOf(db_tel);  //登记的手机号

        int updata = db.update("info", values, "login_tel=?", new String[]{args1});

        Toast.makeText(MainActivity.this, "更新了" + updata + "行", Toast.LENGTH_LONG).show();

        db.close();

 

        String args2=String.valueOf("3new");  //新的手机号

        Log.d("000114","新的手机号为:"+args2);

 

        //下次免登录直接到新的手机号上面来

        SharedPreferences sharedPreferences=getSharedPreferences("userInfo",MODE_PRIVATE);

        SharedPreferences.Editor editor = sharedPreferences.edit();

        editor.putString("USER_NAME", "3new");

        editor.putString("PASSWORD","333");

        editor.commit();

 

        //免登录验证

        sp = this.getSharedPreferences("userInfo", Context.MODE_PRIVATE);

        editor_tel=sp.getString("USER_NAME",null);

        editor_pasd=sp.getString("PASSWORD",null);

        Log.d("00147","editor_tel is :"+editor_tel+" , editor_pasd is "+editor_pasd);

        Boolean islogin= TextUtils.isEmpty(editor_tel) || TextUtils.isEmpty(editor_pasd);

        Log.d("00148","islogin(是否为空) is :"+islogin);

        if(!islogin){

            Intent intent=new Intent(MainActivity.this,MainActivity.class);

            intent.putExtra("login_tel", editor_tel);//传值过去

            startActivity(intent);

        }

    }

 

猜你喜欢

转载自blog.csdn.net/qq_38110571/article/details/82109594