最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2020年10月21日 15:55:38   作者:Red&&Black  
這篇文章主要為大家詳細(xì)介紹了Android SQLite數(shù)據(jù)庫連接實(shí)現(xiàn)登錄功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android SQLite數(shù)據(jù)庫連接實(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:width="0.01dp"
      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">
<LinearLayout

        android: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:id="@+id/usn"/>

        <!-- 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:id="@+id/username"/>
      </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:id="@+id/密碼"/>
        <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:id="@+id/password"/>
      </LinearLayout>

    </LinearLayout>

    <Button
        android: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:id="@+id/login"/>
        
</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、版本號(hào)
     */
    final DatabaseHelper databaseHelper = new DatabaseHelper(this,"emis.db",null,2);

    //獲得讀取數(shù)據(jù)庫權(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ù)庫的對(duì)象
    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,"用戶名或密碼錯(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:id="@+id/output"
      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è)試:

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

相關(guān)文章

  • 了解Android OpenGLES2.0(一)

    了解Android OpenGLES2.0(一)

    OpenGLES2.0是一個(gè)功能強(qiáng)大,調(diào)用方便的底層圖形庫,這篇文章主要為大家詳細(xì)介紹了Android OpenGLES2.0的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • 優(yōu)化Gradle提升Gradle編譯速度

    優(yōu)化Gradle提升Gradle編譯速度

    今天小編就為大家分享一篇關(guān)于優(yōu)化Gradle提升Gradle編譯速度的文章,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2018-10-10
  • Android自定義PopWindow帶動(dòng)畫向下彈出效果

    Android自定義PopWindow帶動(dòng)畫向下彈出效果

    這篇文章主要為大家詳細(xì)介紹了Android自定義PopWindow帶動(dòng)畫向下彈出效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • 百度地圖實(shí)現(xiàn)小車規(guī)劃路線后平滑移動(dòng)功能

    百度地圖實(shí)現(xiàn)小車規(guī)劃路線后平滑移動(dòng)功能

    這篇文章主要介紹了百度地圖實(shí)現(xiàn)小車規(guī)劃路線后平滑移動(dòng)功能,本文是小編寫的一個(gè)demo,通過效果圖展示的非常直白,需要的朋友可以參考下
    2020-01-01
  • Android 異步任務(wù) 設(shè)置 超時(shí)使用handler更新通知功能

    Android 異步任務(wù) 設(shè)置 超時(shí)使用handler更新通知功能

    這篇文章主要介紹了Android 異步任務(wù) 設(shè)置 超時(shí)使用handler更新通知,文中給大家提到了使用AsyncTask設(shè)置請(qǐng)求超時(shí)的注意事項(xiàng) ,需要的朋友可以參考下
    2017-12-12
  • Android完全退出應(yīng)用程序的方法

    Android完全退出應(yīng)用程序的方法

    這篇文章主要介紹了Android完全退出應(yīng)用程序的方法,實(shí)例分析了Android退出應(yīng)用程序的相關(guān)方法與實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-09-09
  • Android編程實(shí)現(xiàn)手機(jī)拍照的方法詳解

    Android編程實(shí)現(xiàn)手機(jī)拍照的方法詳解

    這篇文章主要介紹了Android編程實(shí)現(xiàn)手機(jī)拍照的方法,結(jié)合實(shí)例形式分析了Android實(shí)現(xiàn)手機(jī)拍照的操作步驟與具體細(xì)節(jié),需要的朋友可以參考下
    2016-11-11
  • Android超簡(jiǎn)單懸浮窗使用教程

    Android超簡(jiǎn)單懸浮窗使用教程

    這篇文章主要介紹了Android超簡(jiǎn)單懸浮窗使用教程,本文分步驟給大家介紹了使用前需要依賴庫,給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2021-09-09
  • anroid開發(fā)教程之spinner下拉列表的使用示例

    anroid開發(fā)教程之spinner下拉列表的使用示例

    這篇文章主要介紹了anroid的spinner下拉列表的使用示例,需要的朋友可以參考下
    2014-04-04
  • Android中回調(diào)接口的使用介紹

    Android中回調(diào)接口的使用介紹

    回調(diào)接口在完成某些特殊的功能時(shí)還是蠻有用的,下面為大家分享下具體的使用方法,感興趣的朋友可以參考下哈
    2013-06-06

最新評(píng)論

五指山市| 临西县| 霸州市| 仙桃市| 承德县| 开化县| 滨海县| 灵璧县| 板桥市| 海门市| 甘洛县| 安丘市| 满洲里市| 邯郸市| 罗定市| 乌什县| 大连市| 邯郸市| 金华市| 晴隆县| 宜兰市| 五原县| 中山市| 大石桥市| 英德市| 屏南县| 钟祥市| 镇原县| 乌兰浩特市| 乌恰县| 西畴县| 吕梁市| 巴林左旗| 灌云县| 彰化县| 施秉县| 米脂县| 会昌县| 辽阳县| 湘潭县| 连平县|