23.实战演练--个人主页

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.LoginTest"
        tools:targetApi="31">
        <activity
            android:name=".EditProfileActivity"
            android:exported="false" />
        <activity
            android:name=".UserProfileActivity"
            android:exported="false" />
        <activity
            android:name=".LoginActivity"
            android:exported="true"
            android:label="登录">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".RegisterActivity"
            android:exported="false"
            android:label="注册" />
        <activity
            android:name=".MainActivity"
            android:exported="false"
            android:label="首页" />
    </application>

</manifest>

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyBtnStyle">
        <item name="android:textColor">@color/white</item>
        <item name="android:textSize">25sp</item>
        <item name="android:background">@drawable/btn_bg_selector</item>
        <item name="android:layout_marginTop">20dp</item>
        <item name="android:layout_marginRight">20dp</item>
        <item name="android:layout_marginLeft">20dp</item>
    </style>

    <style name="MyEditStyle">
        <item name="android:textSize">18sp</item>
        <item name="android:background">@drawable/edit_text_bg</item>
        <item name="android:paddingLeft">10dp</item>
        <item name="android:layout_height">50dp</item>
    </style>
</resources>

<resources>
    <string name="app_name">LoginTest</string>
    
    <string-array name="cities">
        <item>北京</item>
        <item>上海</item>
        <item>天津</item>
        <item>深圳</item>
        <item>广州</item>
        <item>福建</item>
        <item>江苏</item>
        <item>浙江</item>
        <item>江西</item>
        <item>湖北</item>
    </string-array>
</resources>

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="black">#FF000000</color>
    <color name="white">#FFFFFFFF</color>

    <color name="green_200">#C5E1A5</color>
    <color name="green_500">#8BC34A</color>
    <color name="green_700">#689F38</color>

    <color name="colorPrimary">@color/green_500</color>
    <color name="colorPrimaryDark">@color/green_700</color>
    <color name="accent">#F4511E</color>

    <color name="teal_200">#FF03DAC5</color>
    <color name="teal_700">#FF018786</color>
</resources>

<vector android:autoMirrored="true" android:height="24dp"
    android:tint="#093243" android:viewportHeight="24"
    android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="@android:color/white" android:pathData="M6.23,20.23l1.77,1.77l10,-10l-10,-10l-1.77,1.77l8.23,8.23z"/>
</vector>

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/colorPrimary"/>
    <item android:state_pressed="false" android:drawable="@color/colorPrimaryDark"/>
</selector>

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <stroke android:width="3dp" android:color="@color/colorPrimary"/>

    <corners android:radius="10dp"/>
</shape>

<?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=".MainActivity"
    android:orientation="vertical">
    <TextView
        android:id="@+id/tv_content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="40sp"
        android:layout_marginTop="30dp"
        android:text="欢迎你:"
        android:layout_gravity="center_horizontal"/>
    <Button
        android:id="@+id/btn_logout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="退出登录"
        android:textSize="25sp"
        android:layout_margin="20dp"
        android:background="@drawable/btn_bg_selector"/>
</LinearLayout>

package com.example.logintest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
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 MainActivity extends AppCompatActivity implements View.OnClickListener {
    private Button btn_logout;
    private TextView tvContent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn_logout = findViewById(R.id.btn_logout);
        btn_logout.setOnClickListener(this);

        tvContent = findViewById(R.id.tv_content);

        Intent intent = getIntent();
        String account = intent.getStringExtra("account");
        tvContent.setText("欢迎你:"+account);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn_logout) {
            SharedPreferences spf = getSharedPreferences("spfRecord",MODE_PRIVATE);
            SharedPreferences.Editor edit = spf.edit();
            edit.putBoolean("isLogin",false);
            edit.apply();

            Intent intent = new Intent(this, LoginActivity.class);
            startActivity(intent);
            this.finish();
        }
    }
}

<?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=".RegisterActivity"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="40dp"
        android:gravity="center_vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="账        号:"
            android:textSize="25sp"/>
        <EditText
            android:id="@+id/et_account"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:hint="请输入用户名或手机号"
            android:textSize="18sp"
            android:layout_marginLeft="10dp"
            android:paddingLeft="5dp"
            android:inputType="text"
            android:background="@drawable/edit_text_bg"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="40dp"
        android:gravity="center_vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密        码:"
            android:textSize="25sp"/>
        <EditText
            android:id="@+id/et_password"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:hint="请输入密码"
            android:textSize="18sp"
            android:layout_marginLeft="10dp"
            android:paddingLeft="5dp"
            android:inputType="numberPassword"
            android:background="@drawable/edit_text_bg"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="40dp"
        android:gravity="center_vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="确认密码:"
            android:textSize="25sp"/>
        <EditText
            android:id="@+id/et_password_confirm"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:hint="再次输入密码"
            android:textSize="18sp"
            android:layout_marginLeft="10dp"
            android:paddingLeft="5dp"
            android:inputType="numberPassword"
            android:background="@drawable/edit_text_bg"/>
    </LinearLayout>

    <Button
        android:id="@+id/btn_register"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="注册"
        android:textSize="25sp"
        android:background="@drawable/btn_bg_selector"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"/>
    <CheckBox
        android:id="@+id/rb_agree"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/colorPrimary"
        android:text="同意用户协议?"
        android:layout_gravity="left"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="10dp"/>
</LinearLayout>

package com.example.logintest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
    private Button btnRegister;
    private EditText etAccount,etPass,etPassConfirm;
    private CheckBox rbAgree;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        btnRegister = findViewById(R.id.btn_register);
        btnRegister.setOnClickListener(this);

        etAccount = findViewById(R.id.et_account);
        etAccount.setOnClickListener(this);

        etPass = findViewById(R.id.et_password);
        etPass.setOnClickListener(this);

        etPassConfirm = findViewById(R.id.et_password_confirm);
        etPassConfirm.setOnClickListener(this);

        rbAgree = findViewById(R.id.rb_agree);
        rbAgree.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        String name = etAccount.getText().toString();
        String pass = etPass.getText().toString();
        String passConfirm = etPassConfirm.getText().toString();
        if (view.getId() == R.id.btn_register) {
            if (TextUtils.isEmpty(name)) {
                Toast.makeText(RegisterActivity.this, "用户名不能为空", Toast.LENGTH_LONG).show();
                return;
            }
            if (TextUtils.isEmpty(pass)) {
                Toast.makeText(RegisterActivity.this, "密码不能为空", Toast.LENGTH_LONG).show();
                return;
            }
            if (!TextUtils.equals(pass, passConfirm)) {
                Toast.makeText(RegisterActivity.this, "密码不一致", Toast.LENGTH_LONG).show();
                return;
            }
            if (!rbAgree.isChecked()) {
                Toast.makeText(RegisterActivity.this, "请同意用户协议", Toast.LENGTH_LONG).show();
                return;
            }

            SharedPreferences spf = getSharedPreferences("spfRecorid",MODE_PRIVATE);
            SharedPreferences.Editor edit = spf.edit();
            edit.putString("account",name);
            edit.putString("password",pass);

            Intent intent = new Intent();
            Bundle bundle = new Bundle();
            bundle.putString("account",name);
            bundle.putString("password",pass);
            intent.putExtras(bundle);
            setResult(0,intent);

            Toast.makeText(RegisterActivity.this, "注册成功", Toast.LENGTH_LONG).show();
            this.finish();
        }
    }
}

<?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=".LoginActivity"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="40dp"
        android:gravity="center_vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="账号:"
            android:textSize="25sp"/>
        <EditText
            android:id="@+id/et_account"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:hint="请输入用户名或手机号"
            android:textSize="18sp"
            android:layout_marginLeft="10dp"
            android:paddingLeft="5dp"
            android:inputType="text"
            android:background="@drawable/edit_text_bg"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="40dp"
        android:gravity="center_vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密码:"
            android:textSize="25sp"/>
        <EditText
            android:id="@+id/et_password"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:hint="请输入密码"
            android:textSize="18sp"
            android:layout_marginLeft="10dp"
            android:paddingLeft="5dp"
            android:inputType="numberPassword"
            android:background="@drawable/edit_text_bg"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp">
        <CheckBox
            android:id="@+id/cb_remember"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="记住密码"/>
        <CheckBox
            android:id="@+id/cb_auto_login"
            android:visibility="visible"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="自动登录"
            android:layout_marginLeft="40dp"/>
    </LinearLayout>
    <Button
        android:id="@+id/btn_Login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="登录"
        style="@style/MyBtnStyle"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"/>
    <TextView
        android:id="@+id/to_register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/colorPrimary"
        android:text="还没有账号?"
        android:layout_gravity="right"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"/>

</LinearLayout>

package com.example.logintest;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
    public static final int REQUEST_CODE_REGISTER = 1;
    private Button btnLogin;
    private EditText etAccount,etPassword;
    private CheckBox cbRemember,cbAutoLogin;
    private TextView toRegister;

    private String userName = "admin";
    private String pass = "1234";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initView();
        initData();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn_Login) {
            String account = etAccount.getText().toString();
            String passWord = etPassword.getText().toString();
            if (TextUtils.isEmpty(userName)){
                Toast.makeText(LoginActivity.this, "对不起,你还没注册账号!", Toast.LENGTH_LONG).show();
                return;
            }
            if (TextUtils.equals(account, userName)) {
                if (TextUtils.equals(passWord, pass)) {
                    Toast.makeText(LoginActivity.this, "恭喜你,登陆成功!", Toast.LENGTH_LONG).show();
                    if (cbRemember.isChecked()){
                        SharedPreferences spf = getSharedPreferences("spfRecord",MODE_PRIVATE);
                        SharedPreferences.Editor edit = spf.edit();
                        edit.putString("account",account);
                        edit.putString("password",passWord);
                        edit.putBoolean("isRemember",true);
                        if (cbAutoLogin.isChecked()){
                            edit.putBoolean("isLogin",true);
                        }else {
                            edit.putBoolean("isLogin",false);
                        }
                        edit.apply();
                    }else {
                        SharedPreferences spf = getSharedPreferences("spfRecord",MODE_PRIVATE);
                        SharedPreferences.Editor edit = spf.edit();
                        edit.putBoolean("isRemember",false);
                        edit.apply();
                    }
                    Intent intent = new Intent(LoginActivity.this, UserProfileActivity.class);
                    intent.putExtra("account",account);
                    startActivity(intent);
                    LoginActivity.this.finish();
                } else {
                    Toast.makeText(LoginActivity.this, "密码错误!", Toast.LENGTH_LONG).show();
                }
            } else {
                Toast.makeText(LoginActivity.this, "用户名错误!", Toast.LENGTH_LONG).show();
            }
        } else if (view.getId() == R.id.to_register) {
            Intent intent = new Intent(this, RegisterActivity.class);

            startActivityForResult(intent, REQUEST_CODE_REGISTER);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_REGISTER && resultCode == 0 && data!=null){
            Bundle extras = data.getExtras();
            String account = extras.getString("account", "");
            String password = extras.getString("password", "");

            etAccount.setText(account);
            etPassword.setText(password);

            userName = account;
            pass = password;
        }
    }

    private void initView(){
        btnLogin = findViewById(R.id.btn_Login);
        btnLogin.setOnClickListener(this);

        etAccount = findViewById(R.id.et_account);
        etAccount.setOnClickListener(this);

        etPassword = findViewById(R.id.et_password);
        etPassword.setOnClickListener(this);

        cbRemember = findViewById(R.id.cb_remember);
        cbRemember.setOnCheckedChangeListener(this::onCheckedChangedResult);
        cbAutoLogin = findViewById(R.id.cb_auto_login);
        cbAutoLogin.setOnCheckedChangeListener(this::onCheckedChanged);

        toRegister = findViewById(R.id.to_register);
        toRegister.setOnClickListener(this);
    }
    private void initData() {
        SharedPreferences spf = getSharedPreferences("spfRecord",MODE_PRIVATE);
        boolean isRemember = spf.getBoolean("isRemember",false);
        boolean isLogin = spf.getBoolean("isLogin",false);

        String account = spf.getString("account","");
        String password = spf.getString("password","");

        if (isLogin){
            Intent intent = new Intent(LoginActivity.this, UserProfileActivity.class);
            intent.putExtra("account",account);
            startActivity(intent);
            LoginActivity.this.finish();
        }


        userName = account;
        pass = password;

        if (isRemember){
            etAccount.setText(account);
            etPassword.setText(password);
            cbRemember.setChecked(true);
        }
    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        if (b){
            cbRemember.setChecked(true);
        }
    }

    public void onCheckedChangedResult(CompoundButton compoundButton, boolean b) {
        if (!b){
            cbAutoLogin.setChecked(false);
        }
    }
}

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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=".UserProfileActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:background="@color/colorPrimary">

            <ImageView
                android:id="@+id/iv_avatar"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_centerInParent="true"
                android:src="@mipmap/ic_launcher" />

            <TextView
                android:id="@+id/tv_nick_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/iv_avatar"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:text="admin"
                android:textColor="@color/white"
                android:textSize="14sp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/tv_nick_name"
                android:gravity="center"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/tv_gender"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/iv_avatar"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="5dp"
                    android:text="男"
                    android:textColor="@color/white"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/tv_age"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/iv_avatar"
                    android:layout_centerHorizontal="true"
                    android:layout_marginLeft="5dp"
                    android:layout_marginTop="5dp"
                    android:text="21岁"
                    android:textColor="@color/white"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/tv_city"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/iv_avatar"
                    android:layout_centerHorizontal="true"
                    android:layout_marginLeft="5dp"
                    android:layout_marginTop="5dp"
                    android:text="北京"
                    android:textColor="@color/white"
                    android:textSize="14sp" />
            </LinearLayout>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:gravity="center_vertical"
            android:paddingLeft="10dp">

            <TextView
                android:id="@+id/tv_account"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="账号"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/tv_account_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/tv_account"
                android:layout_toRightOf="@id/tv_account"
                android:gravity="center"
                android:text="admin"
                android:textSize="20sp" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:gravity="center_vertical"
            android:paddingLeft="10dp">

            <TextView
                android:id="@+id/tv_birth_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="出生时间"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/tv_birth_time_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@id/tv_birth_time"
                android:layout_toRightOf="@id/tv_birth_time"
                android:gravity="center"
                android:text="123234"
                android:textSize="20sp" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:gravity="center_vertical"
            android:paddingLeft="10dp">

            <TextView
                android:id="@+id/tv_home"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="城市"
                android:textSize="20sp"
                tools:ignore="InvalidId" />

            <TextView
                android:id="@+id/tv_home_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@id/tv_home"
                android:layout_toRightOf="@id/tv_home"
                android:gravity="center"
                android:text="北京"
                android:textSize="20sp" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:gravity="center_vertical"
            android:paddingLeft="10dp">

            <TextView
                android:id="@+id/tv_school"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="学校"
                android:textSize="20sp"
                tools:ignore="InvalidId" />

            <TextView
                android:id="@+id/tv_school_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@id/tv_school"
                android:layout_toRightOf="@id/tv_school"
                android:gravity="center"
                android:text="北京大学"
                android:textSize="20sp" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:gravity="center_vertical"
            android:paddingLeft="10dp">

            <TextView
                android:id="@+id/tv_sign"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="个人签名"
                android:textSize="20sp"
                tools:ignore="InvalidId" />

            <TextView
                android:id="@+id/tv_sign_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@id/tv_sign"
                android:layout_toRightOf="@id/tv_sign"
                android:gravity="center"
                android:text="这个人没有设置任何签名"
                android:textSize="14sp" />
        </RelativeLayout>

        <Button
            android:id="@+id/btn_toEdit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="@drawable/btn_bg_selector"
            android:text="编辑资料" />

        <Button
            android:id="@+id/btn_logout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="@drawable/btn_bg_selector"
            android:text="退出登录" />
    </LinearLayout>
</ScrollView>

package com.example.logintest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class UserProfileActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView tvNickName,tvAccount,tvAge,tvGender,tvCity,tvHome,tvSchool,tvSign,tvBirthdayTime;
    private String birthDayTime;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_profile);

        Button btn_toEdit = findViewById(R.id.btn_toEdit);
        btn_toEdit.setOnClickListener(this);
        Button btn_logout = findViewById(R.id.btn_logout);
        btn_logout.setOnClickListener(this);

        initView();
    }

    @Override
    protected void onResume() {
        super.onResume();
        initData();
    }


    private void initData() {
        getDataFromspf();
    }

    private void getDataFromspf() {
        SharedPreferences spfRecord = getSharedPreferences("spfRecord",MODE_PRIVATE);
        String account = spfRecord.getString("account","");
        String nick_name = spfRecord.getString("nick_name","");
        String city = spfRecord.getString("city","");
        String gender = spfRecord.getString("gender","");
        String school = spfRecord.getString("school","");
        String birth_day_time = spfRecord.getString("birth_day_time","");
        String sign = spfRecord.getString("sign","");
        String home = spfRecord.getString("home","");
        String age = getAgeByBirthDay(birthDayTime);

        tvAccount.setText(account);
        tvNickName.setText(nick_name);
        tvAge.setText(age);
        tvHome.setText(home);
        tvSchool.setText(school);
        tvSign.setText(sign);
        tvBirthdayTime.setText(birth_day_time);
        tvGender.setText(gender);
        tvCity.setText(city);
    }

    private String getAgeByBirthDay(String birthDayTime) {
        if (TextUtils.isEmpty(birthDayTime)){
            return "";
        }
        try {
            int index = birthDayTime.indexOf("年");
            String result = birthDayTime.substring(0,index);

            int parseInt = Integer.parseInt(result);
            return String.valueOf(2021-parseInt);
        }catch (Exception e){
            e.printStackTrace();
        }
        return "";
    }

    private void initView() {
        tvAccount = findViewById(R.id.tv_account_text);
        tvNickName = findViewById(R.id.tv_nick_name);
        tvAge = findViewById(R.id.tv_age);
        tvHome = findViewById(R.id.tv_home_text);
        tvSchool = findViewById(R.id.tv_school_text);
        tvSign = findViewById(R.id.tv_sign_text);
        tvBirthdayTime = findViewById(R.id.tv_birth_time_text);
        tvGender = findViewById(R.id.tv_gender);
        tvCity = findViewById(R.id.tv_city);

    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn_toEdit){
            Intent intent = new Intent(this, EditProfileActivity.class);
            startActivity(intent);
        } else if (view.getId() == R.id.btn_logout) {
            SharedPreferences spf = getSharedPreferences("spfRecord",MODE_PRIVATE);
            SharedPreferences.Editor edit = spf.edit();
            edit.putBoolean("isLogin",false);
            edit.apply();

            Intent intent = new Intent(this, LoginActivity.class);
            startActivity(intent);
            this.finish();
        }
    }
}

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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=".EditProfileActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="250dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:text="更换头像"
                android:textSize="20sp" />

            <ImageView
                android:id="@+id/iv_avatar"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_centerInParent="true"
                android:src="@mipmap/ic_launcher" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/iv_avatar"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:orientation="horizontal">

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/btn_bg_selector"
                    android:text="拍照" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:background="@drawable/btn_bg_selector"
                    android:text="相册" />
            </LinearLayout>

        </RelativeLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:gravity="center_vertical"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv_account"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="账号:"
                android:textSize="25sp" />

            <EditText
                android:id="@+id/et_account_text"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="10dp"
                android:background="@drawable/edit_text_bg"
                android:hint="请输入你的账号"
                android:paddingLeft="5dp"
                android:textSize="18sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:gravity="center_vertical"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv_nick_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="昵称:"
                android:textSize="25sp" />

            <EditText
                android:id="@+id/et_nick_name_text"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="10dp"
                android:background="@drawable/edit_text_bg"
                android:hint="请输入你的账号"
                android:paddingLeft="5dp"
                android:textSize="18sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:gravity="center_vertical"
            android:orientation="horizontal">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="性别"
                android:textSize="20sp"/>
            <RadioGroup
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="center">
                <RadioButton
                    android:id="@+id/rb_boy"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="男"/>
                <RadioButton
                    android:id="@+id/rb_girl"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="女"
                    android:layout_marginLeft="10dp"/>
            </RadioGroup>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv_birth_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="出生日期:"
                android:textSize="25sp" />

            <TextView
                android:id="@+id/tv_birth_time_text"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_marginLeft="10dp"
                android:text="1998年3月23 15点25分"
                android:paddingLeft="5dp"
                android:textSize="18sp" />
            <ImageView
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_gravity="center_vertical"
                android:src="@drawable/baseline_arrow_forward_24"
                android:layout_marginLeft="30dp"
                />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:gravity="center_vertical"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv_home"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="城市:"
                android:textSize="25sp" />

            <androidx.appcompat.widget.AppCompatSpinner
                android:id="@+id/sp_city"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="10dp"
                android:background="@drawable/edit_text_bg"
                android:entries="@array/cities"
                android:spinnerMode="dropdown"
                android:paddingLeft="5dp"
                android:textSize="18sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:gravity="center_vertical"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv_school"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="学校:"
                android:textSize="25sp" />

            <EditText
                android:id="@+id/et_school_text"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="10dp"
                android:background="@drawable/edit_text_bg"
                android:hint="请输入你的学校"
                android:paddingLeft="5dp"
                android:textSize="18sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:gravity="center_vertical"
            android:orientation="vertical">

            <TextView
                android:id="@+id/tv_sign"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="个人签名:"
                android:textSize="25sp" />

            <EditText
                android:id="@+id/et_sign_text"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:background="@drawable/edit_text_bg"
                android:hint="请设置你的个人签名"
                android:textSize="18sp" />
        </LinearLayout>


        <Button
            android:id="@+id/btn_save"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="@drawable/btn_bg_selector"
            android:text="保存" />

    </LinearLayout>
</ScrollView>

package com.example.logintest;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatSpinner;

import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.TimePicker;

public class EditProfileActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText etNickName,etAccount,etSchool,etSign;
    private  TextView tvBirthDayTime;
    private RadioButton rbBoy,rbGirl;
    private AppCompatSpinner spinnerCity;
    private String[] cities;
    private int selectedCityPosition;
    private String selectedCity;
    private String birthDay;
    private String birthDayTime;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_profile);
        Button btn_save = findViewById(R.id.btn_save);
        btn_save.setOnClickListener(this);
        
        initView();
        initData();
        
        initEvent();
    }

    private void initView() {
        etAccount = findViewById(R.id.et_account_text);
        etNickName = findViewById(R.id.et_nick_name_text);
        etSchool = findViewById(R.id.et_school_text);
        etSign = findViewById(R.id.et_sign_text);

        tvBirthDayTime = findViewById(R.id.tv_birth_time_text);
        rbBoy = findViewById(R.id.rb_boy);
        rbGirl = findViewById(R.id.rb_girl);
        spinnerCity = findViewById(R.id.sp_city);
    }
    private void initData() {
        cities = getResources().getStringArray(R.array.cities);

        getDataFromspf();
    }
    private void getDataFromspf() {
        SharedPreferences spfRecord = getSharedPreferences("spfRecord",MODE_PRIVATE);
        String account = spfRecord.getString("account","");
        String nick_name = spfRecord.getString("nick_name","");
        String age = spfRecord.getString("age","");
        String city = spfRecord.getString("city","");
        String gender = spfRecord.getString("gender","");
        String school = spfRecord.getString("school","");
        String birth_day_time = spfRecord.getString("birth_day_time","");
        String sign = spfRecord.getString("sign","");
        String home = spfRecord.getString("home","");

        etAccount.setText(account);
        etNickName.setText(nick_name);
        etSchool.setText(age);
        etSign.setText(home);
        tvBirthDayTime.setText(birthDayTime);

        if (TextUtils.equals("男",gender)){
            rbBoy.setChecked(true);
        }

        if (TextUtils.equals("女",gender)){
            rbGirl.setChecked(true);
        }

        for (int i = 0; i < cities.length; i++) {
            if (TextUtils.equals(cities[i],city)){
                selectedCityPosition = i;
                break;
            }
        }

        spinnerCity.setSelection(selectedCityPosition);
    }

    private void initEvent() {
        spinnerCity.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                selectedCityPosition = i;
                selectedCity = cities[i];
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });

        tvBirthDayTime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new DatePickerDialog(EditProfileActivity.this, new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
                        int realMonth = i1+1;
                        birthDay = i+"年"+realMonth+"月"+i2+"日";

                        popTimePick();
                    }

                },2024,2,17).show();
            }
        });
    }
    private void popTimePick() {
        new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker timePicker, int i, int i1) {
                birthDayTime = birthDay+i+"时"+i1+"分";
                tvBirthDayTime.setText(birthDayTime);
            }
        },12,36,true).show();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn_save){
            String account = etAccount.getText().toString();
            String sign = etSign.getText().toString();
            String school = etSchool.getText().toString();
            String nickName = etNickName.getText().toString();

            String gender = "男";
            if (rbBoy.isChecked()){
                gender = "男";
            }
            if (rbGirl.isChecked()){
                gender = "女";
            }

            SharedPreferences spfRecord = getSharedPreferences("spfRecord",MODE_PRIVATE);
            SharedPreferences.Editor editor = spfRecord.edit();
            editor.putString("account",account);
            editor.putString("sign",sign);
            editor.putString("school",school);
            editor.putString("nick_name",nickName);
            editor.putString("birth_day_time",birthDayTime);
            editor.putString("city",selectedCity);
            editor.putString("gender",gender);
            editor.apply();

            this.finish();
        }
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/329520.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【latex】参考文献排版前移,在最前面引用\usepackage{url}

【LaTeX】参考文献排版前移&#xff0c;在最前面引用\usepackage{url} 写在最前面完整解决步骤请教申申latex编译报错解决方案 写在最前面 参考文献从21开始排版前移了 解决方案&#xff1a;在最前面加一行 \usepackage{url}完整解决步骤 请教申申 申申yyds&#xff01;&am…

VsCode插件开发之ChatGPT实战

基础介绍&#x1f5e3;︎ VSCode 是采用了 Electron开发的跨平台的桌面应用&#xff0c;它兼容 Mac、Windows 和Linux&#xff0c;可以构建出三个平台的应用程序&#xff0c;基于VSCode开发的插件&#xff0c;同样也能在多个平台同时运行。 VSCode布局&#xff1a; 插件开发&…

IDEA插件中的postman,你试试

Postman是大家最常用的API调试工具&#xff0c;那么有没有一种方法可以不用手动写入接口到Postman&#xff0c;即可进行接口调试操作&#xff1f;今天给大家推荐一款IDEA插件&#xff1a;Apipost Helper&#xff0c;写完代码就可以调试接口并一键生成接口文档&#xff01;而且还…

JAVA方法及练习

目录 Java方法的定义以及调用 带返回值方法的定义和调用 方法的重载 方法大练习 练习1 练习2 练习3 练习4 Java方法的定义以及调用 方法练习package java方法;public class fangfa1 {public static void main(String[] args) {xuexi();}//定义一个方法public static vo…

UG全参数化建模

在UG全参数化建模中&#xff0c;可以先创建表达式再设计图形&#xff0c;也可先设计图形再关联表达式 UG表达式类型有&#xff1a;数字&#xff0c;字符串&#xff0c;布尔&#xff0c;整数&#xff0c;点&#xff0c;矢量&#xff0c;列表 数字&#xff1a;在数字类型中&…

【Python学习】Python学习20- 面向对象(3)

目录 【Python学习】Python学习20- 面向对象&#xff08;1&#xff09; 前言类属性与方法类的私有属性类的私有方法实例 单下划线、双下划线、头尾双下划线说明&#xff1a;参考 文章所属专区 Python学习 前言 本章节主要说明Python的面向对象的处理最后一部分。 类属性与方…

【已解决】fatal: Authentication failed for ‘https://github.com/.../‘

文章目录 异常原因解决方法 异常原因 在 Linux 服务器上使用git push命令&#xff0c;输入用户名和密码之后&#xff0c;总会显示一个报错&#xff1a; fatal: Authentication failed for https://github.com/TianJiaQi-Code/Linux.git/ # 致命&#xff1a;无法通过验证访问起…

.NET国产化改造探索(三)、银河麒麟安装.NET 8环境

随着时代的发展以及近年来信创工作和…废话就不多说了&#xff0c;这个系列就是为.NET遇到国产化需求的一个闭坑系列。接下来&#xff0c;看操作。 上一篇介绍了如何在银河麒麟操作系统上安装人大金仓数据库&#xff0c;这篇文章详细介绍下在银河麒麟操作系统上安装.NET8环境。…

MySQL入门篇:约束(主键,外键),多表查询(连接查询,联合查询,子查询)

目录 1.约束1.约束分类2.演示3.外键约束1.语法2.删除/更新行为 2.多表查询1.多表关系2.多表查询分类1.连接查询1.内连接2.外连接1.左外连接2.右外连接 3.自连接 2.联合查询(union)3.子查询1.标量子查询2.列子查询3.行子查询4.表子查询 1.约束 ①概念:约束是作用于表中字段上的规…

Python4Delphi安装及编译

1.下载或直接克隆python4delphi组件资源到指定目录,我这里下载到Components文件夹下,并对下载的文件夹进行了重命名为(P4D),重命名不是必须的 下载地址:https://github.com/pyscripter/python4delphi 2.安装 2.1在已下载的目录下进入Install文件夹,双击MultiInstaller.exe…

如何快速打造属于自己的接口自动化测试框架

1 接口测试 接口测试是对系统或组件之间的接口进行测试&#xff0c;主要是校验数据的交换&#xff0c;传递和控制管理过程&#xff0c;以及相互逻辑依赖关系。 接口自动化相对于UI自动化来说&#xff0c;属于更底层的测试&#xff0c;这样带来的好处就是测试收益更大&#xff…

Stream API 函数式编程 - 告别for循环,代码竟能写的如此优雅?

目录 一、Stream API 函数式编程 1.1、Stream 简介 a&#xff09;为什么引入 Stream&#xff1f;Stream 的出现就是为了让关于集合的操作更加简单&#xff1a; b&#xff09;Stream 的特性&#xff1a; c&#xff09;对stream的操作分为为两类&#xff0c;中间操作 和 结束…

训练DAMO-YOLO(damoyolo_tinynasL25_S.py)

文章目录 参考链接1 准备数据1.1 转为COCO格式1.2 指明数据路径 2 设置训练配置文件&#xff0c;在configs/damoyolo_tinynasL25_S.py进行如下两块修改2.1 关于训练参数的设置2.2 根据自己数据集设置 3 开始训练4 调用tools/eval.py进行测试5 训练时可能遇到的报错5.1 RuntimeE…

运维工具之iptables命令

运维工具之iptables命令 1.iptables防火墙介绍 ​ iptables其实并不是真正的防火墙&#xff0c;我们可以理解成一个客户端代理&#xff0c;用户通过 IPTables这个代理&#xff0c;将用户的安全设定执行到对应的"安全框架"中&#xff0c;这个"安全框架"才…

c语言 编译与链接

编译与链接 翻译环境和执行环境翻译环境1.1预编译1.2编译1.3汇编&#xff08;ASM&#xff09;2.链接 执行环境最后给大家附上一张关于本节知识内容的图供大家更好理解~ ![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/522d488885ba44d99aa504d6b21c88d5.png) &…

LLaMa2 Chat gpt 大模型本地部署初体验

一直想在自己电脑或者测试环境随便找台服务器尝试部署一下“大模型”&#xff0c;但“大模型”对于内存和GPU的要求令人望而却步&#xff0c;层出不穷的各种术语也令人困惑&#xff0c;有点难以下手。 经过一段时间&#xff0c;在百度千帆大模型平台、讯飞星火大模型平台、魔搭…

【期末考试】网络综合复习宝典

相关链接 网络复习思维导图&#xff08;HCIP&#xff09;https://www.edrawsoft.cn/viewer/public/s/038e2370897928 详述循环冗余校验CRC码https://blog.csdn.net/liht_1634/article/details/124328005?app_version6.2.6&codeapp_1562916241&csdn_share_tail%7B%22…

【送书活动七期】CMeet系列 技术生态沙龙:技术人职业交流会·杭州场-转鸿蒙 对应用开发来说是否是职业发展新机会

CSDN致力于促进城市区域内尖端新兴技术开发者交流,提供开放自由的切磋平台。在近期热议的话题中,“华为鸿蒙系统不再兼容安卓应用”的消息成了程序员们广泛关注并引发思考的问题。 因此便有了我们此次的活动探讨议题! 目录 题外话开场简单介绍活动主办方介绍活动话题讨论升职加…

IDEA连接Github⭐️使用Git工具上传本地文件到远程仓库

环境准备 已安装IDEA开发工具&#xff0c;Git版本管理工具&#xff0c;已注册GitHub账号 需要先准备好这些环境&#xff0c;可以自行搜索教程&#xff0c;下面的安装是基于这里的环境上操作的 目录 一、需要提供SSH公钥 ​二、Github配置SSH公钥 ​三、IDEA配置连接 四、连…

C++ 多条件比较的几种实现方式

文章目录 1 sort()使用自定义比较器1.1 在类内部定义比较器 -- 声明为静态成员函数1.2 在函数内部定义比较器 -- lamda表达式1.3 全局函数比较器 2 重载运算符<2.1 在结构体中重载运算符<2.2 在类中重载运算符< 3 重写仿函数bool operator()4 使用pair排序5 priority_…