色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

Android SQLite數據庫連接實現登錄功能

瀏覽:140日期:2022-09-22 09:12:02

本文實例為大家分享了Android SQLite數據庫連接實現登錄功能的具體代碼,供大家參考,具體內容如下

布局文件

border.xml

<?xml version='1.0' encoding='utf-8'?><shape xmlns:android='http://schemas.android.com/apk/res/android' ><!-- 布局的背景顏色--><!-- <solid android:color='#FFFFFF' />--><!-- 邊框線的粗細和顏色--> <stroke android: android:color='#000' /> <padding android:bottom='5dp' android:left='5dp' android:right='5dp' android:top='5dp' /><!-- 圓角--> <corners android:radius='5dp' /></shape>

<?xml version='1.0' encoding='utf-8'?><android.support.constraint.ConstraintLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:app='http://schemas.android.com/apk/res-auto' xmlns:tools='http://schemas.android.com/tools' android:layout_width='match_parent' android:layout_height='match_parent' tools:context='.MainActivity'><LinearLayoutandroid:padding='5dp'android:background='@drawable/border'android:orientation='vertical'android:layout_gravity='center_horizontal'android:layout_width='360dp'android:layout_height='112dp'> <LinearLayout android:orientation='horizontal' android:layout_gravity='center_horizontal' android:layout_width='match_parent' android:layout_height='50dp'><ImageView android:layout_marginRight='15dp' android:layout_gravity='center_vertical' android:layout_width='30dp' android:layout_height='30dp' app:srcCompat='@drawable/usn' android: /><!-- android:background='@null' 去掉下劃線--><EditText android:singleLine='true' android:background='@null' android:layout_width='match_parent' android:layout_height='match_parent' android:inputType='text' android:hint='用戶名' android:ems='10' android: /> </LinearLayout> <!-- 水平線--> <View android:layout_height='0.5dip' android:background='#686868' android:layout_width='match_parent'/> <LinearLayout android:orientation='horizontal' android:layout_gravity='center_horizontal' android:layout_width='match_parent' android:layout_height='50dp'><ImageView android:layout_marginRight='15dp' android:layout_gravity='center_vertical' android:layout_width='30dp' android:layout_height='30dp' app:srcCompat='@drawable/pwd' android: /><EditText android:singleLine='true' android:background='@null' android:layout_width='match_parent' android:layout_height='match_parent' android:inputType='textPassword' android:hint='密碼' android:ems='10' android: /> </LinearLayout> </LinearLayout> <Buttonandroid:layout_gravity='center_horizontal'android:background='#EF8D89'android:layout_marginTop='20dp'android:text='登 錄'android:onClick='userLogin'android:layout_width='360dp'android:layout_height='wrap_content' android: /></android.support.constraint.ConstraintLayout>

MainActivity類

public class MainActivity extends AppCompatActivity implements View.OnClickListener{ //訪問數據庫的類 SQLiteDatabase db; //定義常量,作為消息的key public final static String MESSAGE_KEY='com.android2'; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /** * (參數)1、context MainActivity * 2、name 數據庫名 * 3、 * 4、版本號 */ final DatabaseHelper databaseHelper = new DatabaseHelper(this,'emis.db',null,2); //獲得讀取數據庫權限 db = databaseHelper.getReadableDatabase(); setContentView(R.layout.activity_main); } /*響應*/ private void userLogin() { EditText et1 = findViewById(R.id.username); String username = et1.getText().toString(); EditText et2 = findViewById(R.id.password); String password = et2.getText().toString(); //游標類Cursor 負責生成讀寫數據庫的對象 Cursor cursor = db.rawQuery('SELECT * FROM users WHERE username=? AND password=?',new String[]{username,password}); //數據庫中有此數據,登錄成功 if(cursor.getCount()>0){ Intent intent = new Intent(this,ReceiveActivity.class); intent.putExtra(MESSAGE_KEY,username); startActivity(intent); } else{ Toast.makeText(MainActivity.this,'用戶名或密碼錯誤!',Toast.LENGTH_SHORT).show(); } }}

ReceiveActivity類及布局

<?xml version='1.0' encoding='utf-8'?><LinearLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:tools='http://schemas.android.com/tools' xmlns:app='http://schemas.android.com/apk/res-auto' android:layout_width='match_parent' android:layout_height='match_parent' tools:context='.ReceiveActivity'> <TextView android:textSize='24dp' android:layout_gravity='center_vertical' android: android:layout_width='match_parent' android:layout_height='match_parent' /></LinearLayout>

package com.android02;import android.content.Intent;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.TextView;public class ReceiveActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_receive); //獲取intent引用 Intent intent = getIntent(); //以MESSAGE_KEY獲取獲取編輯框文字 String message = intent.getStringExtra(MainActivity.MESSAGE_KEY); //以id獲取TextView TextView textView = findViewById(R.id.output); //顯示message textView.setText('歡迎!'+message); }}

測試:

Android SQLite數據庫連接實現登錄功能

Android SQLite數據庫連接實現登錄功能

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
主站蜘蛛池模板: 成人精品一区二区三区中文字幕 | 久久九九国产精品怡红院 | avove旗袍丝袜高跟啪啪 | 欧美色欧美亚洲高清在线视频 | 一级特级毛片免费 | www.亚洲天堂 | 日本加勒比一区 | 中文字幕在线日韩 | 欧美三级 欧美一级 | 成人在线手机视频 | 九七在线视频 | 久久精品免视看国产明星 | 亚洲国产成人久久综合区 | 手机看片神马午夜片 | 久久不射网 | 亚洲天堂男人天堂 | www射射一区 | 国产精品国产三级国产a | 久久国产毛片 | 小明日韩在线看看永久区域 | 成人看片黄a在线看 | 成人毛片18女人毛片免费 | 免费高清欧美一区二区视频 | 久久精品三级视频 | 毛片看看 | 韩国毛片在线 | 女初高中福利视频在线观看 | 中文在线三级中文字幕 | 欧美大尺码毛片 | 欧美成人在线影院 | 中文字幕一区二区三区在线观看 | 成人在线观看网址 | 成人黄色免费网站 | 不卡无毒免费毛片视频观看 | 久在草 | 国产自愉自愉全免费高清 | 精品国产日韩亚洲一区在线 | 日本三级一区二区三区 | 亚洲综合视频 | 亚洲国产激情在线一区 | 亚洲视频在线免费看 |