国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

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

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

本文實(shí)例為大家分享了Android SQLite數(shù)據(jù)庫(kù)連接實(shí)現(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' />--><!-- 邊框線的粗細(xì)和顏色--> <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ù)庫(kù)的類 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ù)庫(kù)名 * 3、 * 4、版本號(hào) */ final DatabaseHelper databaseHelper = new DatabaseHelper(this,'emis.db',null,2); //獲得讀取數(shù)據(jù)庫(kù)權(quán)限 db = databaseHelper.getReadableDatabase(); setContentView(R.layout.activity_main); } /*響應(yīng)*/ 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(); //游標(biāo)類Cursor 負(fù)責(zé)生成讀寫數(shù)據(jù)庫(kù)的對(duì)象 Cursor cursor = db.rawQuery('SELECT * FROM users WHERE username=? AND password=?',new String[]{username,password}); //數(shù)據(jù)庫(kù)中有此數(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,'用戶名或密碼錯(cuò)誤!',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); }}

測(cè)試:

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

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

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 久在线视频 | 依依成人综合网 | 欧美在线一区视频 | 日本一区二区三区在线 视频观看免费 | 久久韩国| 欧美亚洲视频 | 欧美一级乱理片免费观看 | 亚洲人成影院在线高清 | 中国一级大黄大片 | 国产黄色片在线免费观看 | a级国产精品片在线观看 | 欧美自拍视频在线 | 国产精品久久免费 | 日本高清不卡在线观看 | 欧美在线区 | 国产精品99久久久久久小说 | 欧美久草 | 视频综合网 | 国产欧美在线播放 | 欧美精品区 | 欧美色操 | 成人午夜久久精品 | 日韩三级中文 | 免费看美女午夜大片 | 国产成人精品视频免费 | 国产精品免费_区二区三区观看 | 日本三级香港三级网站 | 国产成人3p视频免费观看 | 亚洲男人精品 | 2021国产精品自在拍在线播放 | 亚洲综合在线另类色区奇米 | 亚洲欧美一区二区三区在线 | 久久99国产精一区二区三区 | 国产在线精品一区二区三区 | 青青自拍视频一区二区三区 | 看看免费a一片欧 | 男人和女人的做刺激性视频 | 老太婆性杂交毛片 | 爱爱爱久久久久久久 | 一区二区三区观看 | avav在线看 |