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

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

Android SQLite數(shù)據(jù)庫連接實現(xiàn)登錄功能

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

本文實例為大家分享了Android SQLite數(shù)據(jù)庫連接實現(xiàn)登錄功能的具體代碼,供大家參考,具體內(nèi)容如下

布局文件

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{ //訪問數(shù)據(jù)庫的類 SQLiteDatabase db; //定義常量,作為消息的key public final static String MESSAGE_KEY='com.android2'; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /** * (參數(shù))1、context MainActivity * 2、name 數(shù)據(jù)庫名 * 3、 * 4、版本號 */ final DatabaseHelper databaseHelper = new DatabaseHelper(this,'emis.db',null,2); //獲得讀取數(shù)據(jù)庫權限 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 負責生成讀寫數(shù)據(jù)庫的對象 Cursor cursor = db.rawQuery('SELECT * FROM users WHERE username=? AND password=?',new String[]{username,password}); //數(shù)據(jù)庫中有此數(shù)據(jù),登錄成功 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數(shù)據(jù)庫連接實現(xiàn)登錄功能

Android SQLite數(shù)據(jù)庫連接實現(xiàn)登錄功能

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

標簽: Android
相關文章:
主站蜘蛛池模板: 6080伦理久久亚洲精品 | 国产久草视频 | 三级毛片基地 | 欧美激情精品久久久久 | 欧美高清另类自拍视频在线看 | 在线看亚洲 | 国产在线一区二区三区欧美 | 成人在线视频国产 | 日韩第五页 | 国产在线步兵一区二区三区 | 亚洲精品成人一区二区aⅴ 亚洲精品成人一区二区www | 国产精品久久久久久久久 | 国产一毛片| 国产第一页久久亚洲欧美国产 | 亚州免费视频 | 欧美日韩亚洲成色二本道三区 | 精品亚洲成a人在线观看 | 日韩国产欧美一区二区三区在线 | 日本大臿亚洲香蕉大片 | 久操免费在线 | 国产成人精品视频频 | 国产波多野结衣中文在线播放 | 久久国产精品久久精 | 99久久国产免费中文无字幕 | 国产精品久久久久久亚洲伦理 | 亚洲成人免费在线 | 欧美日韩精品国产一区二区 | 久草免费资源视频 | a毛片免费全部播放完整成 a毛片免费全部在线播放毛 | 欧美大屁股精品毛片视频 | 久久草网站 | 欧美乱大交xxxxx在线观看 | 免费国产成人午夜在线观看 | 欧美成在人线a免费 | 精品国产欧美另类一区 | 亚洲成年www | 99久久免费国产香蕉麻豆 | 久久亚洲精品中文字幕亚瑟 | 午夜免费理论片a级 | 国产精品久久毛片蜜月 | 成人一级片在线观看 |