目錄
目錄
功能說(shuō)明?
登錄頁(yè)面
注冊(cè)頁(yè)面
登錄后界面
點(diǎn)擊頭像出現(xiàn)側(cè)滑界面,并顯示用戶信息
點(diǎn)擊編輯按鈕進(jìn)入信息編輯頁(yè)面
?保存后返回
?用戶名已更改
跳轉(zhuǎn)網(wǎng)頁(yè)
相關(guān)代碼
布局
登錄界面
?注冊(cè)界面
?信息顯示界面
?主界面
實(shí)現(xiàn)側(cè)滑布局?
信息編輯界面
網(wǎng)頁(yè)顯示界面?
manifest?
邏輯代碼?
?LoginActivity
RegisterActivity
EditInformationActivity
RelaxActivity
StudyActivity
SlideActivity
實(shí)現(xiàn)側(cè)滑功能
網(wǎng)頁(yè)activity
網(wǎng)頁(yè)配置——SetWebView.class
?進(jìn)度條加載——SetProgressBar.class
?數(shù)據(jù)庫(kù)helper
user類
ToastUtil
結(jié)語(yǔ)
2022.11.12更新
功能說(shuō)明?
登錄頁(yè)面
注冊(cè)頁(yè)面
能夠驗(yàn)證用戶名是否已存在,并判斷兩次密碼是否一致
?
登錄后界面
點(diǎn)擊頭像出現(xiàn)側(cè)滑界面,并顯示用戶信息
當(dāng)前用戶無(wú)信息
?
點(diǎn)擊編輯按鈕進(jìn)入信息編輯頁(yè)面
編輯信息
?
?保存后返回
信息頁(yè)面顯示更改后的信息
?用戶名已更改
修改用戶名后,下次登錄需要填寫更改后的用戶名
跳轉(zhuǎn)網(wǎng)頁(yè)
點(diǎn)擊按鈕進(jìn)入相應(yīng)的網(wǎng)頁(yè) ,這里點(diǎn)擊? “長(zhǎng)知識(shí)”>>“菜鳥學(xué)編程”
?
相關(guān)代碼
布局
登錄界面
<?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"
android:background="@drawable/bg_blue_orange"
android:orientation="vertical"
tools:context=".LoginActivity">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="100dp"
android:text="歡迎使用這個(gè)app!"
android:textColor="@color/white"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:layout_marginTop="80dp"
android:background="@drawable/bt_humditiy"
android:orientation="horizontal">
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="用戶名:"
android:textColor="@color/white"
android:layout_marginLeft="5dp"
android:textSize="18dp" />
<EditText
android:id="@+id/Ed_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/input_username"
android:inputType="textPersonName"
android:textColor="@color/white" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:layout_marginTop="30dp"
android:background="@drawable/bt_humditiy"
android:orientation="horizontal">
<TextView
android:id="@+id/textView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="密碼:"
android:textColor="@color/white"
android:layout_marginLeft="5dp"
android:textSize="18dp" />
<EditText
android:id="@+id/Ed_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="@string/input_password"
android:inputType="textPassword"
android:textColor="@color/white"
android:textColorHighlight="@color/white" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:orientation="horizontal">
<Button
android:id="@+id/bt_login"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/bt_humditiy"
android:text="@string/login"
android:textColor="@color/white"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:textSize="20sp" />
<Button
android:id="@+id/bt_register"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/bt_humditiy"
android:text="@string/registered"
android:textColor="@color/white"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:textSize="24sp" />
</LinearLayout>
</LinearLayout>
?注冊(cè)界面
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
android:background="@drawable/bg_blue_orange"
tools:context=".RegisterActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/register_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="注冊(cè)"
android:textSize="40dp"
android:textColor="@color/white"
android:layout_marginTop="20dp"
android:layout_marginStart="160dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"
android:background="@drawable/bt_humditiy"
android:layout_marginHorizontal="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:textColor="@color/white"
android:textSize="18dp"
android:layout_marginLeft="5dp"
android:text="用戶名:" />
<EditText
android:id="@+id/set_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="請(qǐng)輸入用戶名:"
android:inputType="textPersonName" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@drawable/bt_humditiy"
android:layout_marginHorizontal="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/textView8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:textColor="@color/white"
android:textSize="18dp"
android:layout_marginLeft="5dp"
android:text="密碼:" />
<EditText
android:id="@+id/set_userPassword1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="請(qǐng)輸入密碼:"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@drawable/bt_humditiy"
android:layout_marginHorizontal="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/textView9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:textColor="@color/white"
android:textSize="18dp"
android:layout_marginLeft="5dp"
android:text="確認(rèn)密碼:" />
<EditText
android:id="@+id/set_userPassword2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="再次輸入密碼:"
android:inputType="textPassword" />
</LinearLayout>
<Button
android:id="@+id/bt_startRegister"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:layout_marginHorizontal="100dp"
android:background="@drawable/bt_humditiy"
android:textColor="@color/white"
android:textSize="20dp"
android:text="點(diǎn)擊注冊(cè)" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
?信息顯示界面
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="270dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/bg_purple_miror">
<TextView
android:id="@+id/tv_userInformation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="個(gè)人信息"
android:textColor="@color/white"
android:textSize="25dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="3"
android:text="年齡:"
android:textColor="@color/white"
android:textSize="22dp" />
<TextView
android:id="@+id/tv_userAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:layout_weight="1"
android:textSize="22dp"
android:layout_marginTop="20dp"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_sex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="性別:"
android:textColor="@color/white"
android:textSize="22dp" />
<TextView
android:id="@+id/tv_userSex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/white"
android:textSize="22dp"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_favorite"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="愛好:"
android:textColor="@color/white"
android:textSize="22dp" />
<TextView
android:id="@+id/tv_userFavorite"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/white"
android:textSize="22dp"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="20dp"
android:orientation="vertical">
<TextView
android:id="@+id/tv_signature"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="個(gè)性簽名:"
android:textColor="@color/white"
android:textSize="20dp" />
<TextView
android:id="@+id/tv_userSignature"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="9"
android:textColor="@color/white"
android:textSize="22dp"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/bt_toEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:background="@color/bitGrey"
android:paddingLeft="180dp"
android:text="編輯>"
android:textColor="@color/white"
android:textSize="30dp" />
</LinearLayout>
</LinearLayout>
?主界面
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/bg_purple">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="10dp">
<ImageView
android:id="@+id/iv_head"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:src="@mipmap/head1"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:scaleType="centerCrop"/>
<TextView
android:id="@+id/tv_username"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="user_冰川"
android:textSize="30dp"
android:layout_margin="10dp"
android:textColor="@color/white"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:layout_marginTop="200dp"
android:orientation="vertical">
<Button
android:id="@+id/btn_study"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="40dp"
android:text="長(zhǎng)知識(shí)"
android:background="@drawable/bt_humditiy"
android:textColor="@color/white"/>
<Button
android:id="@+id/btn_relax"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="40dp"
android:text="找點(diǎn)樂子"
android:background="@drawable/bt_humditiy"
android:textColor="@color/white"/>
</LinearLayout>
</LinearLayout>
實(shí)現(xiàn)側(cè)滑布局?
<?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"
android:orientation="vertical"
tools:context=".SlideActivity">
<com.example.myfirst.util.SlideMenu
android:id="@+id/slideMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- 信息界面布局-->
<include layout="@layout/layout_menu" />
<!-- 主界面布局-->
<include
layout="@layout/layout_main"
android:layout_width="wrap_content"
android:layout_height="743dp" />
</com.example.myfirst.util.SlideMenu>
</LinearLayout>
信息編輯界面
<?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"
android:orientation="vertical"
android:background="@drawable/bg_green_blue"
tools:context=".EditInformationActivity">
<TextView
android:id="@+id/Tv_EditInformation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="信息編輯"
android:textColor="@color/white"
android:textSize="30sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bitGrey"
android:layout_marginTop="120dp"
android:orientation="horizontal">
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textColor="@color/white"
android:textSize="25dp"
android:layout_marginLeft="10dp"
android:text="用戶名:" />
<EditText
android:id="@+id/Et_EditUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:textColor="@color/white"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bitGrey"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textColor="@color/white"
android:textSize="25dp"
android:layout_marginLeft="10dp"
android:text="年齡:" />
<EditText
android:id="@+id/Et_editAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:textColor="@color/white"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bitGrey"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textColor="@color/white"
android:textSize="25dp"
android:layout_marginLeft="10dp"
android:text="性別:" />
<RadioGroup
android:id="@+id/rg_sex"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1">
<RadioButton
android:id="@+id/rdB_male"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="男" />
<RadioButton
android:id="@+id/rdB_female"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="女" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bitGrey"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textColor="@color/white"
android:textSize="25dp"
android:layout_marginLeft="10dp"
android:text="愛好:" />
<EditText
android:id="@+id/Et_editFavorite"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:textColor="@color/white"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bitGrey"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textColor="@color/white"
android:textSize="25dp"
android:layout_marginLeft="10dp"
android:text="個(gè)性簽名:" />
<EditText
android:id="@+id/Et_editSignature"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:textColor="@color/white"
android:textSize="20dp" />
</LinearLayout>
<Button
android:id="@+id/bt_saveInformation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:layout_marginHorizontal="100dp"
android:background="@drawable/bt_humditiy"
android:textColor="@color/white"
android:textSize="30dp"
android:text="保存" />
</LinearLayout>
網(wǎng)頁(yè)顯示界面?
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".RunoobActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:id="@+id/pb_run_oob"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<WebView
android:id="@+id/wv_runOob"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
manifest?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirst">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/this_app"
android:label="@string/app_name"
android:roundIcon="@mipmap/this_app"
android:supportsRtl="true"
android:theme="@style/Theme.Myfirst"
android:usesCleartextTraffic="true">
<activity
android:name=".FlowerActivity"
android:exported="false" />
<activity
android:name=".EndlessLakeActivity"
android:exported="false" />
<activity
android:name=".SpaceActivity"
android:exported="false" />
<activity
android:name=".DeepSeaActivity"
android:exported="false" />
<activity
android:name=".AnswerActivity"
android:exported="false" />
<activity
android:name=".MedicineActivity"
android:exported="false" />
<activity
android:name=".TechnologyMuseumActivity"
android:exported="false" />
<activity
android:name=".RunoobActivity"
android:exported="false" />
<activity
android:name=".EditInformationActivity"
android:exported="false" />
<activity
android:name=".RegisterActivity"
android:exported="false" /> <!-- 防止net::ERR_CLEARTEXT_NOT_PERMITTED -->
<activity
android:name=".WhichoneActivity"
android:exported="false" />
<activity
android:name=".LoopTapActivity"
android:exported="false" />
<activity
android:name=".HenxiangsiActivity"
android:exported="false" />
<activity
android:name=".MikutapActivity"
android:exported="false" />
<activity
android:name=".SummondragonActivity"
android:exported="false" />
<activity
android:name=".EatwhatActivity"
android:exported="false" />
<activity
android:name=".WebZTypeActivity"
android:exported="false" />
<activity
android:name=".RelaxActivity"
android:exported="false" />
<activity
android:name=".StudyActivity"
android:exported="false" />
<activity
android:name=".SlideActivity"
android:exported="true" />
<activity
android:name=".LoginActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
邏輯代碼?
?LoginActivity
package com.example.myfirst;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.example.myfirst.util.DBHelper;
import com.example.myfirst.util.ToastUtil;
import com.example.myfirst.util.User;
import java.util.ArrayList;
public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
//當(dāng)需要用到新的onClick()時(shí),要 implements View.OnClickListener
private Button mBtLogin; //聲明變量
private EditText mEtUser;
private EditText mEtPassword;
private Button mBtRegister;
private DBHelper dbHelper;
public static int userId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mBtLogin = findViewById(R.id.bt_login);
mEtPassword = findViewById(R.id.Ed_password);
mEtUser = findViewById(R.id.Ed_username);
mBtRegister = findViewById(R.id.bt_register);
dbHelper = new DBHelper(this);
mBtLogin.setOnClickListener(this); //當(dāng)需要用到新的onClick()時(shí),就用this
mBtRegister.setOnClickListener(this);
}
public void onClick(View view){
switch (view.getId()){
case R.id.bt_login:
String username = mEtUser.getText().toString().trim();
String password = mEtPassword.getText().toString().trim();
if(!TextUtils.isEmpty(username) && !TextUtils.isEmpty(password)){
ArrayList<User> userData = dbHelper.getData(); //在User list創(chuàng)建一個(gè)實(shí)例userData
boolean judge = false; //并讓userData獲取數(shù)據(jù)庫(kù)里的數(shù)據(jù)
for (int i = 0; i < userData.size(); i++){
User user = userData.get(i);
if (username.equals(user.getName()) && password.equals(user.getPassword())){
judge = true;
userId = i;
break;
} //遍歷user id,當(dāng)輸入的用戶名和密碼與數(shù)據(jù)庫(kù)里的數(shù)據(jù)匹配則judge=true
else {
judge = false;
}
}
if (judge){
ToastUtil.showMsg(LoginActivity.this,"登陸成功!");
Intent intent2 = new Intent(this,SlideActivity.class);
startActivity(intent2);
finish();
}
else {
ToastUtil.showMsg(LoginActivity.this,"用戶名錯(cuò)誤或密碼錯(cuò)誤!");
}
}
else {
ToastUtil.showMsg(LoginActivity.this,"用戶名或密碼不能為空");
}
break;
case R.id.bt_register:
Intent intent1 = new Intent(LoginActivity.this,RegisterActivity.class);
startActivity(intent1);
break;
}
}
public static int getUserId(){
return userId;
}
}
RegisterActivity
package com.example.myfirst;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.example.myfirst.util.DBHelper;
import com.example.myfirst.util.ToastUtil;
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener{
private Button mBtToRegister;
private DBHelper dbHelper;
private EditText mEtSetUsername;
private EditText mEtSetUserPassword1;
private EditText mEtSetUserPassword2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
mEtSetUsername = findViewById(R.id.set_username);
mEtSetUserPassword1 = findViewById(R.id.set_userPassword1);
mEtSetUserPassword2 = findViewById(R.id.set_userPassword2);
mBtToRegister = findViewById(R.id.bt_startRegister);
dbHelper = new DBHelper(this);
mBtToRegister.setOnClickListener(this);
}
public void onClick(View view){
String username = mEtSetUsername.getText().toString().trim();
String password1 = mEtSetUserPassword1.getText().toString().trim();
String password2 = mEtSetUserPassword2.getText().toString().trim();
if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(password1)&& !TextUtils.isEmpty(password2) ) {
if ((password1.equals(password2))) {
if (dbHelper.add(username, password2)){
//將用戶名和密碼加入到數(shù)據(jù)庫(kù)中
Intent intent2 = new Intent(this, LoginActivity.class);
startActivity(intent2);
finish();
ToastUtil.showMsg(RegisterActivity.this,"注冊(cè)成功!");
}
else {
ToastUtil.showMsg(RegisterActivity.this,"該用戶名已存在!");
}
}
else {
ToastUtil.showMsg(RegisterActivity.this,"密碼輸入不一致");
}
}
else {
ToastUtil.showMsg(RegisterActivity.this,"用戶名和密碼不能為空!");
}
}
}
EditInformationActivity
信息編輯activity
package com.example.myfirst;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import com.example.myfirst.util.DBHelper;
import com.example.myfirst.util.ToastUtil;
import com.example.myfirst.util.User;
import java.util.ArrayList;
public class EditInformationActivity extends AppCompatActivity implements View.OnClickListener{
private EditText mEtUsername,mEtAge,mEtFavorite,mEtSignature;
private Button mBtSaveInformation;
private DBHelper dbHelper;
private RadioButton mRbMale,mRbFemale;
private String sexString;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_infor);
mEtUsername = findViewById(R.id.Et_EditUsername);
mEtAge = findViewById(R.id.Et_editAge);
mRbMale = findViewById(R.id.rdB_male);
mRbFemale = findViewById(R.id.rdB_female);
mEtFavorite = findViewById(R.id.Et_editFavorite);
mEtSignature = findViewById(R.id.Et_editSignature);
mBtSaveInformation = findViewById(R.id.bt_saveInformation);
dbHelper = new DBHelper(this);
showRadioButtonIsCheck();
mBtSaveInformation.setOnClickListener(this);
}
private void showRadioButtonIsCheck(){ //定義一個(gè)根據(jù)用戶性別顯示 哪個(gè)radiobutton被選中的方法
ArrayList<User> userData = dbHelper.getData();
User user = userData.get(LoginActivity.getUserId());
if (!(user.getSex() == null)){
if (user.getSex().equals("男")){
mRbMale.setChecked(true);
}else if (user.getSex().equals("女")){
mRbFemale.setChecked(true);
}
}
}
@Override
public void onClick(View view) {
String username = mEtUsername.getText().toString().trim();
String age = mEtAge.getText().toString();
String favorite = mEtFavorite.getText().toString();
String signature = mEtSignature.getText().toString(); //分別獲取輸入的用戶信息
if (!username.isEmpty()){
dbHelper.updateUsername(username);
}
if (!age.isEmpty()){
dbHelper.updateAge(age);
}
if (mRbMale.isChecked()){
sexString = "男";
}else if (mRbFemale.isChecked()){
sexString = "女";
}
dbHelper.updateSex(sexString);
if (!favorite.isEmpty()){
dbHelper.updateFavorite(favorite);
}
if (!signature.isEmpty()){
dbHelper.updateSignature(signature); //分別保存到數(shù)據(jù)庫(kù)中的User表,必須做一個(gè)是否為空的檢查
} //否則表中數(shù)據(jù)可能會(huì)被覆蓋
SlideActivity.slideActivity.finish(); //更改后銷毀原來(lái)的信息顯示頁(yè)面
ToastUtil.showMsg(this,"更改成功");
Intent intent = new Intent(EditInformationActivity.this,SlideActivity.class);
startActivity(intent);
finish();
}
}
RelaxActivity
娛樂
package com.example.myfirst;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class RelaxActivity extends AppCompatActivity {
private Button btnGame1,btnGame2,btnGame3,btnGame4,btnGame5,btnGame6,btnGame7,btnGame8,btnGame9;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_relax);
btnGame1 = findViewById(R.id.bt_game1);
btnGame2 = findViewById(R.id.bt_game2);
btnGame3 = findViewById(R.id.bt_game3);
btnGame4 = findViewById(R.id.bt_game4);
btnGame5 = findViewById(R.id.bt_game5);
btnGame6 = findViewById(R.id.bt_game6);
btnGame7 = findViewById(R.id.bt_game7);
btnGame8 = findViewById(R.id.bt_game8);
btnGame9 = findViewById(R.id.bt_game9);
setClickListener();
}
private class OnClick implements View.OnClickListener{ //新建私有類OnClick,實(shí)現(xiàn)View.OnClickListener
@Override //重寫onClick方法
public void onClick(View view) {
Intent intent = null;
switch (view.getId()){
case R.id.bt_game1:
intent = new Intent(RelaxActivity.this,WebZTypeActivity.class);
break;
case R.id.bt_game2:
intent = new Intent(RelaxActivity.this,EatwhatActivity.class);
break;
case R.id.bt_game3:
intent = new Intent(RelaxActivity.this, SummondragonActivity.class);
break;
case R.id.bt_game4:
intent = new Intent(RelaxActivity.this,WhichoneActivity.class);
break;
case R.id.bt_game5:
intent = new Intent(RelaxActivity.this,MikutapActivity.class);
break;
case R.id.bt_game6:
intent = new Intent(RelaxActivity.this,HenxiangsiActivity.class);
break;
case R.id.bt_game7:
intent = new Intent(RelaxActivity.this, LoopTapActivity.class);
break;
case R.id.bt_game8:
intent = new Intent(RelaxActivity.this, FlowerActivity.class);
break;
case R.id.bt_game9:
intent = new Intent(RelaxActivity.this, EndlessLakeActivity.class);
break;
}
startActivity(intent);
}
}
//設(shè)計(jì)方法
private void setClickListener(){
OnClick onClick = new OnClick(); //在OnClick新建onClick實(shí)體,否則36行OnClick是灰色的,也就是沒被調(diào)用
btnGame1.setOnClickListener(onClick); //每個(gè)button都調(diào)用監(jiān)聽,并用上面的方法
btnGame2.setOnClickListener(onClick);
btnGame3.setOnClickListener(onClick);
btnGame4.setOnClickListener(onClick);
btnGame5.setOnClickListener(onClick);
btnGame6.setOnClickListener(onClick);
btnGame7.setOnClickListener(onClick);
btnGame8.setOnClickListener(onClick);
btnGame9.setOnClickListener(onClick);
}
}
StudyActivity
學(xué)習(xí)
package com.example.myfirst;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.SearchEvent;
import android.view.View;
import android.widget.Button;
public class StudyActivity extends AppCompatActivity {
private Button btnStudy1,btnStudy2,btnStudy3,btnStudy4,btnStudy5,btnStudy6;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_study);
btnStudy1 = findViewById(R.id.btn_study1);
btnStudy2 = findViewById(R.id.btn_study2);
btnStudy3 = findViewById(R.id.btn_study3);
btnStudy4 = findViewById(R.id.btn_study4);
btnStudy5 = findViewById(R.id.btn_study5);
btnStudy6 = findViewById(R.id.btn_study6);
setClickListener();
}
private class OnClick implements View.OnClickListener{ //新建私有類OnClick,與 View.OnClickListener接口對(duì)接
@Override
public void onClick(View view) {
Intent intent = null;
switch (view.getId()){
case R.id.btn_study1:
intent = new Intent(StudyActivity.this,RunoobActivity.class);
break;
case R.id.btn_study2:
intent = new Intent(StudyActivity.this,TechnologyMuseumActivity.class);
break;
case R.id.btn_study3:
intent = new Intent(StudyActivity.this,MedicineActivity.class);
break;
case R.id.btn_study4:
intent = new Intent(StudyActivity.this,AnswerActivity.class);
break;
case R.id.btn_study5:
intent = new Intent(StudyActivity.this,SpaceActivity.class);
break;
case R.id.btn_study6:
intent = new Intent(StudyActivity.this, DeepSeaActivity.class);
break;
}
startActivity(intent);
}
}
private void setClickListener(){
OnClick onClick = new OnClick();
btnStudy1.setOnClickListener(onClick);
btnStudy2.setOnClickListener(onClick);
btnStudy3.setOnClickListener(onClick);
btnStudy4.setOnClickListener(onClick);
btnStudy5.setOnClickListener(onClick);
btnStudy6.setOnClickListener(onClick); //每個(gè)button都調(diào)用監(jiān)聽,并用上面的方法
}
}
SlideActivity
側(cè)滑
package com.example.myfirst;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.myfirst.util.DBHelper;
import com.example.myfirst.util.SlideMenu;
import com.example.myfirst.util.User;
import java.util.ArrayList;
public class SlideActivity extends AppCompatActivity {
private ImageView mIvHead;
private SlideMenu slideMenu;
private Button buttonStudy;
private Button buttonRelax;
private Button buttonToEdit;
private TextView mTvUsername,mTvSex,mTvAge,mTvFavorite,mTvSignature;
private DBHelper dbHelper;
public static SlideActivity slideActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_slide);
slideActivity = this;
mIvHead = findViewById(R.id.iv_head);
slideMenu = findViewById(R.id.slideMenu);
buttonStudy = findViewById(R.id.btn_study);
buttonRelax = findViewById(R.id.btn_relax);
buttonToEdit = findViewById(R.id.bt_toEdit);
mTvUsername = findViewById(R.id.tv_username); //用戶信息顯示控件
mTvSex = findViewById(R.id.tv_userSex);
mTvAge = findViewById(R.id.tv_userAge);
mTvFavorite = findViewById(R.id.tv_userFavorite);
mTvSignature = findViewById(R.id.tv_userSignature);
mIvHead.setOnClickListener(v -> slideMenu.switchMenu());
setClickListener();
dbHelper = new DBHelper(this);
showUserInformation();
}
//由于button太多,設(shè)計(jì)一個(gè)方法,設(shè)計(jì)方法之前寫好要調(diào)用的類
private class OnClick implements View.OnClickListener{ //新建私有類OnClick,實(shí)現(xiàn)View.OnClickListener
@Override //重寫onClick方法
public void onClick(View view) {
Intent intent = null;
switch (view.getId()){
case R.id.btn_study:
intent = new Intent(SlideActivity.this,StudyActivity.class);
break;
case R.id.btn_relax:
intent = new Intent(SlideActivity.this,RelaxActivity.class);
break;
case R.id.bt_toEdit:
intent = new Intent(SlideActivity.this,EditInformationActivity.class);
}
startActivity(intent);
}
}
//設(shè)計(jì)方法
private void setClickListener(){
OnClick onClick = new OnClick(); //在OnClick新建onClick實(shí)體,否則36行OnClick是灰色的,也就是沒被調(diào)用
buttonStudy.setOnClickListener(onClick); //每個(gè)button都調(diào)用監(jiān)聽,并用上面的方法
buttonRelax.setOnClickListener(onClick);
buttonToEdit.setOnClickListener(onClick);
}
private void showUserInformation() { //建立獲取用戶信息的方法
ArrayList<User> userData2 = dbHelper.getData(); //創(chuàng)建User隊(duì)列 userData2
User user = userData2.get(LoginActivity.getUserId()); //創(chuàng)建一個(gè)實(shí)體user,并獲取當(dāng)前用戶id的數(shù)據(jù)
mTvUsername.setText(user.getName());
mTvAge.setText(user.getAge());
mTvSex.setText(user.getSex());
mTvFavorite.setText(user.getFavorite()); //分別獲取用戶信息到TV控件
mTvSignature.setText(user.getSignature());
}
}
實(shí)現(xiàn)側(cè)滑功能
這里是使用了別人封裝好的類,??(順帶一提,小姐姐在b站的教學(xué)視頻很好)?b站材料1-代碼之側(cè)滑界面的java文件_小小小白冷的博客-CSDN博客
package com.example.myfirst.util;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.Scroller;
public class SlideMenu extends FrameLayout {
private View menuView,mainView;
private int menuWidth;
private Scroller scroller;
public SlideMenu(Context context) {
super(context);
init();
}
public SlideMenu(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init(){
scroller = new Scroller(getContext());
}
/**
* 當(dāng)1級(jí)子view全部加載完調(diào)用,可以用初始化子view引用
* 注意這里無(wú)法獲取子view的寬高
*/
@Override
protected void onFinishInflate() {
super.onFinishInflate();
menuView = getChildAt(0);
mainView = getChildAt(1);
menuWidth = menuView.getLayoutParams().width;
}
//使Menu也具有滑動(dòng)功能
public boolean onInterceptTouchEvent(MotionEvent ev){
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
downX = (int) ev.getX();
break;
case MotionEvent.ACTION_MOVE:
int deltaX = (int) (ev.getX() - downX);
if (Math.abs(deltaX) > 8){
return true;
}
break;
}
return super.onInterceptTouchEvent(ev);
}
/**
* s設(shè)置兩個(gè)子view在頁(yè)面上的布局
* @param l:當(dāng)前子view的左邊在父view的坐標(biāo)系的x坐標(biāo)
* @param t:當(dāng)前子view的頂邊在父view的坐標(biāo)系的y坐標(biāo)
* @param r:當(dāng)前子view的寬
* @param b:當(dāng)前子view的高
*/
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
menuView.layout(-menuWidth, 0, 0, b);
mainView.layout(0, 0, r, b);
}
/**
* 處理屏幕滑動(dòng)事件
*/
private int downX;
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
downX = (int) event.getX();
break;
case MotionEvent.ACTION_MOVE:
int moveX = (int) event.getX();
int deltaX = moveX - downX;
int newScrollX = getScrollX() - deltaX;
if (newScrollX < -menuWidth) newScrollX = -menuWidth;
if (newScrollX > 0) newScrollX = 0;
scrollTo(newScrollX, 0);
downX = moveX;
break;
case MotionEvent.ACTION_UP:
//當(dāng)滑動(dòng)距離小于Menu寬度的一半時(shí),平滑滑動(dòng)到主頁(yè)面
if(getScrollX()>-menuWidth/2){
closeMenu();
}else {
//當(dāng)滑動(dòng)距離大于Menu寬度的一半時(shí),平滑滑動(dòng)到Menu頁(yè)面
openMenu();
}
break;
}
return true;
}
//關(guān)閉menu
private void closeMenu(){
scroller.startScroll(getScrollX(),0,0-getScrollX(),0,400);
invalidate();
}
//打開menu
private void openMenu(){
scroller.startScroll(getScrollX(),0,-menuWidth-getScrollX(),0,400);
invalidate();
}
/**
* Scroller不主動(dòng)去調(diào)用這個(gè)方法
* 而invalidate()可以調(diào)用這個(gè)方法
* invalidate->draw->computeScroll
*/
public void computeScroll(){
super.computeScroll();
if(scroller.computeScrollOffset()){
//返回true,表示動(dòng)畫沒結(jié)束
scrollTo(scroller.getCurrX(),0);
invalidate();
}
}
/**
* 切換菜單的開和關(guān)
*/
public void switchMenu(){
if(getScrollX()==0){
openMenu();
}else {
closeMenu();
}
}
}
網(wǎng)頁(yè)activity
每個(gè)網(wǎng)頁(yè)activity的內(nèi)容步驟都一樣,這里以菜鳥編程為例
package com.example.myfirst;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import com.example.myfirst.util.SetProgressBar;
import com.example.myfirst.util.SetWebView;
public class RunoobActivity extends AppCompatActivity {
private WebView webView;
private String url = "https://www.runoob.com/";
private ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_runoob);
webView = findViewById(R.id.wv_runOob);
progressBar = findViewById(R.id.pb_run_oob);
SetProgressBar.setProgressBar(webView,progressBar);
SetWebView.setWebView(webView,url);
}
}
網(wǎng)頁(yè)配置——SetWebView.class
package com.example.myfirst.util;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class SetWebView {
public static void setWebView(WebView webView,String url){
webView.getSettings().setSupportZoom(true); //設(shè)置可以支持縮放
webView.getSettings().setBuiltInZoomControls(true); //設(shè)置出現(xiàn)縮放工具
webView.getSettings().setUseWideViewPort(true); //擴(kuò)大比例的縮放
webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
//自適應(yīng)屏幕,也就是不能左右滑動(dòng)
webView.getSettings().setLoadWithOverviewMode(true); //加載完全縮小的WebView
webView.getSettings().setJavaScriptEnabled(true); //支持JavaScript
webView.getSettings().setAppCacheEnabled(true); //開啟應(yīng)用緩存
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); //設(shè)置緩存模式
webView.getSettings().setDomStorageEnabled(true); //開啟 DOM storage API 功能
webView.setWebViewClient(new WebViewClient(){ //防止訪問網(wǎng)頁(yè)時(shí)跳轉(zhuǎn)到外部頁(yè)面
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) { //防止跳轉(zhuǎn)到外部瀏覽器
return false;
}
});
webView.loadUrl(url);
}
}
?進(jìn)度條加載——SetProgressBar.class
package com.example.myfirst.util;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ProgressBar;
public class SetProgressBar { //單獨(dú)建立一個(gè)加載進(jìn)度條的類和方法
public static void setProgressBar(WebView webView,ProgressBar progressBar){
webView.setWebChromeClient(new WebChromeClient(){
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
if (newProgress == 100){
progressBar.setVisibility(View.GONE); //加載完成后消失
}else {
progressBar.setVisibility(View.VISIBLE); //未加載完成則可見
progressBar.setProgress(newProgress); //讓控件獲取當(dāng)前加載進(jìn)度
}
}
});
}
}
?數(shù)據(jù)庫(kù)helper
package com.example.myfirst.util;
import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
public class DBHelper extends SQLiteOpenHelper {
private SQLiteDatabase db;
public DBHelper(Context context){ //構(gòu)造函數(shù)
super(context,"db_thisApp",null,1);
db = getReadableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table if not exists user(" +
"_id integer primary key autoincrement,"+
"name text,"+
"password text," +
"sex text," +
"age text," +
"favorite text," +
"signature text" +
")");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists user");
onCreate(db);
}
public boolean add(String name, String password){ //驗(yàn)證用戶名是否已存在并注冊(cè)
boolean judge2 = true;
ArrayList<User> userData = this.getData(); //在User list創(chuàng)建一個(gè)實(shí)例userData,并讓userData獲取數(shù)據(jù)庫(kù)里的數(shù)據(jù)
for (int i = 0; i < userData.size(); i++){
User user = userData.get(i);
if (name.equals(user.getName())){
judge2 = false;
break;
} //遍歷user id,當(dāng)輸入的用戶名已存在則false
}
if (judge2){
db.execSQL("insert into user(name,password) values(?,?)", new Object[]{name,password});
}
return judge2;
} // 需要用Object[]把值傳進(jìn) ?中
public void delete(String name,String password){
db.execSQL("delete from user where name = and password =" + name + password);
}
public void update(String name,String password){
db.execSQL("update user set password = ?",new Object[]{password});
}
public void updateUsername(String name){
db.execSQL("update user set name = ?", new Object[]{name}); //創(chuàng)建一個(gè)更新用戶信息的DB方法
}
public void updateSex(String sex){
db.execSQL("update user set sex = ?", new Object[]{sex});
}
public void updateAge(String age){
db.execSQL("update user set age = ?", new Object[]{age});
}
public void updateFavorite(String favorite){
db.execSQL("update user set favorite = ?", new Object[]{favorite});
}
public void updateSignature(String signature){
db.execSQL("update user set signature = ?", new Object[]{signature});
}
public ArrayList<User> getData(){
//從數(shù)據(jù)庫(kù)獲取數(shù)據(jù)到list中
ArrayList<User> userList = new ArrayList<User>(); //隊(duì)列,以User結(jié)構(gòu)建立隊(duì)列,也就是建立User隊(duì)列
Cursor cursor = db.query("user",null,null,
null,
null,
null,
"name desc");
while (cursor.moveToNext()){ //因?yàn)関alue must be>0,所以不能使用moveToFirst,否則程序會(huì)崩潰:
@SuppressLint("Range") String name = cursor.getString(cursor.getColumnIndex("name"));
@SuppressLint("Range") String password = cursor.getString(cursor.getColumnIndex("password"));
@SuppressLint("Range") String sex = cursor.getString(cursor.getColumnIndex("sex"));
@SuppressLint("Range") String age = cursor.getString(cursor.getColumnIndex("age"));
@SuppressLint("Range") String favorite = cursor.getString(cursor.getColumnIndex("favorite"));
@SuppressLint("Range") String signature = cursor.getString(cursor.getColumnIndex("signature"));
userList.add(new User(name,password,sex,age,favorite,signature));
}
cursor.close(); //游標(biāo)一定要關(guān)掉?。?!不然遍歷過后會(huì)停留在最后一個(gè)位置,語(yǔ)句的位置也很講究
return userList; //從表中遍歷的值依次存入list中
}
}
?這里考慮到真實(shí)情況下,用戶進(jìn)去可能只更新一種屬性,所以把用戶的每種屬性實(shí)現(xiàn)了單獨(dú)更新
user類
package com.example.myfirst.util;
public class User { //構(gòu)造User結(jié)構(gòu)
private String name;
private String password;
private String sex,age,favorite,signature;
public User(String name,String password,String sex,String age,String favorite,String signature){
this.name = name;
this.password = password;
this.sex = sex;
this.age = age;
this.favorite = favorite;
this.signature = signature;
}
public String getName() {
return name;
}
public String getPassword() {
return password;
}
public String getSex(){
return sex;
}
public String getAge(){
return age;
}
public String getFavorite(){
return favorite;
}
public String getSignature(){
return signature;
}
}
ToastUtil
這個(gè)是用來(lái)學(xué)習(xí)而創(chuàng)建的,上面的一些activity都用到了這里面的方法,無(wú)關(guān)緊要,可以直接Toast.makeText()
package com.example.myfirst.util;
import android.content.Context;
import android.widget.Toast;
public class ToastUtil {
public static Toast mToast;
public static void showMsg(Context context,String msg){
if(mToast == null){
mToast = Toast.makeText(context,msg,Toast.LENGTH_SHORT);
}
else{
mToast.setText(msg);
}
mToast.show();
}
}
結(jié)語(yǔ)
這個(gè)項(xiàng)目是邊學(xué)邊做的,所以有些注釋看起來(lái)是多余的,而且有些地方肯定不夠好,有時(shí)間再學(xué)習(xí)并實(shí)現(xiàn)? 用戶上傳頭像功能,搜索并添加好友功能
2022.11.12更新
下面是整個(gè)項(xiàng)目的壓縮包,需要的可以自取
鏈接:https://pan.baidu.com/s/1vvN-xUjXGXVjJri4RWofQQ?pwd=vjif?
提取碼:vjif
項(xiàng)目里還加了更換頭像的功能,不過只適應(yīng)較低的安卓版本,大概不超過安卓9吧,個(gè)別手機(jī)系統(tǒng)也不行,比如小米和vivo文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-426310.html
這是7月弄的,很就沒碰了,最近在弄微信小程序,所以要是有什么問題問我可能答不上來(lái),請(qǐng)見諒文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-426310.html
到了這里,關(guān)于安卓studio 個(gè)人課設(shè)項(xiàng)目:“這個(gè)app“——實(shí)現(xiàn)注冊(cè)登錄,顯示用戶信息功能,并跳轉(zhuǎn)對(duì)應(yīng)網(wǎng)頁(yè)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!