第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何修復(fù) sharedpreference 以保存我的數(shù)據(jù)并跳過(guò)活動(dòng)?

如何修復(fù) sharedpreference 以保存我的數(shù)據(jù)并跳過(guò)活動(dòng)?

呼啦一陣風(fēng) 2023-06-04 15:00:05
我想使用“共享首選項(xiàng)”來(lái)保存我的用戶(hù)名和密碼,它已保存但在我第二次打開(kāi)該應(yīng)用程序時(shí)不起作用。XML:<?xml version="1.0" encoding="utf-8"?>     <android.support.constraint.ConstraintLayout       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="com.home.seesion10.Login_page"android:layoutDirection="rtl"android:textDirection="rtl"android:background="@color/textShiri"><ImageView    android:id="@+id/img_ghorme"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    app:srcCompat="@drawable/cirlcleghormesabzi"    android:layout_marginTop="1500dp"    app:layout_constraintTop_toTopOf="parent"    android:layout_marginLeft="100dp"    app:layout_constraintLeft_toLeftOf="parent"    app:layout_constraintRight_toRightOf="parent"    app:layout_constraintBottom_toBottomOf="parent"    app:layout_constraintHorizontal_bias="0.0"    app:layout_constraintVertical_bias="0.902"    android:layout_marginStart="100dp" /><TextView    android:id="@+id/tv_user"    android:layout_width="0dp"    android:layout_height="wrap_content"    android:layout_marginLeft="8dp"    android:layout_marginRight="15dp"    android:layout_marginTop="20dp"    android:text="??? ??????"    android:textSize="15sp"    android:visibility="invisible"    app:layout_constraintHorizontal_bias="0.0"    app:layout_constraintLeft_toLeftOf="parent"    app:layout_constraintRight_toRightOf="parent"    app:layout_constraintTop_toTopOf="parent" /><EditText    android:id="@+id/tx_user"    android:layout_width="0dp"    android:layout_height="wrap_content"    android:layout_marginLeft="80dp"    android:layout_marginRight="30dp"    android:layout_marginTop="10dp"<Button    android:id="@+id/btn_login" </android.support.constraint.ConstraintLayout>我希望當(dāng)我為用戶(hù)名和密碼編寫(xiě) admin admin 時(shí),它會(huì)保存它,并且我第二次打開(kāi)應(yīng)用程序時(shí)它會(huì)跳過(guò)該登錄頁(yè)面但它不起作用并再次顯示登錄頁(yè)面
查看完整描述

1 回答

?
呼如林

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超3個(gè)贊

您沒(méi)有在使用 sharedPreference 之前初始化它,也沒(méi)有為每個(gè)密鑰對(duì)定義兩個(gè) sharedPreferences。如下更改您的代碼。


public class Login_page extends AppCompatActivity {


TextView tv_user, tv_pass;

EditText tx_user, tx_pass;

Button btn_login;

ImageView img_ghorme;


SharedPreferences save;


public void findall()

{

    tv_user = findViewById(R.id.tv_user);

    tv_pass = findViewById(R.id.tv_pass);

    tx_user = findViewById(R.id.tx_user);

    tx_pass = findViewById(R.id.tx_pass);

    btn_login = findViewById(R.id.btn_login);

    img_ghorme = findViewById(R.id.img_ghorme);

}




public String save_user = "";

public String save_pass = "";


@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main2);


    findall();


    save = getSharedPreferences("userInfo", MODE_PRIVATE);

    save_user = save.getString("username", "");

    save_pass = save.getString("password", "");



    if(save_user.equals("admin") && save_pass.equals("admin"))

    {


        Intent skip = new Intent(Login_page.this, food_page.class);

        startActivity(skip);

    }



    btn_login.setOnClickListener(new View.OnClickListener() {

        @Override

        public void onClick(View v)

        {

            String user = tx_user.getText().toString();

            String pass = tx_pass.getText().toString();



            SharedPreferences.Editor e = save.edit();

            e.putString("username", user);

            e.putString("password", pass);

            e.apply();




            if(user.equals("admin") && pass.equals("admin"))

            {


                Intent food = new Intent(Login_page.this, food_page.class);

                startActivity(food);


            }


            if (!user.equals("admin") || !pass.equals("admin"))

            {


                e.putString("username", "");

                e.putString("password", "");

                e.apply();


                tx_user.setText("");

                tx_pass.setText("");

            }

        }

    });



    Typeface font_shabnam = Typeface.createFromAsset(getAssets(),"fonts/Shabnam.ttf");

    Typeface font_shabnam_light = Typeface.createFromAsset(getAssets(),"fonts/Shabnam_Light.ttf");

    Typeface font_shabnam_bold = Typeface.createFromAsset(getAssets(),"fonts/Shabnam.ttf");


    tv_user.setTypeface(font_shabnam_bold);

    tv_pass.setTypeface(font_shabnam_bold);

    tx_user.setTypeface(font_shabnam_light);

    tx_pass.setTypeface(font_shabnam_light);

    btn_login.setTypeface(font_shabnam_bold);



    Animation ani_rtl = AnimationUtils.loadAnimation(Login_page.this, R.anim.animation_ltr);

    Animation ani_ltr = AnimationUtils.loadAnimation(Login_page.this, R.anim.animation_rtl);

    Animation ani_fade = AnimationUtils.loadAnimation(Login_page.this, R.anim.fade);

    Animation ani_dtu = AnimationUtils.loadAnimation(Login_page.this, R.anim.animation_dtu);


    tv_user.setVisibility(View.VISIBLE);

    tv_user.startAnimation(ani_rtl);


    tv_pass.setVisibility(View.VISIBLE);

    tv_pass.startAnimation(ani_rtl);


    tx_user.setVisibility(View.VISIBLE);

    tx_user.startAnimation(ani_ltr);


    tx_pass.setVisibility(View.VISIBLE);

    tx_pass.startAnimation(ani_ltr);


    btn_login.setVisibility(View.VISIBLE);

    btn_login.startAnimation(ani_fade);


    img_ghorme.startAnimation(ani_dtu);


}


@Override

protected void onPause() {

    super.onPause();

    finish();

}

}


查看完整回答
反對(duì) 回復(fù) 2023-06-04
  • 1 回答
  • 0 關(guān)注
  • 156 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)