admin管理员组

文章数量:1535440

2024年3月5日发(作者:)

安卓简单注册登录的基本代码(Android simple login login basic

code)

登录代码:

包;

进口ty;

进口ialog;

进口;

进口ssdialog;

进口interface;

进口;

进口;

进口database;

进口;

进口inflater;

进口;

进口xt;

进口ew;

公共类登录扩展活动{

/ * *的时候调用首次创建。* /

m_dlog进度对话框;

SQLite数据库MySQL;

查看dialogview;

@Override

public void onCreate(Bundle savedinstancestate){

超级onCreate(savedinstancestate);

setContentView(。主);

MySQL =这。openorcreatedatabase(“学生数据库”,mode_private,null);

尝试

{

MySQL。execsql(“创建表login_t(_id整型主键用户名文本名称文本、密码文本)”);

} catch(异常E){ }

LayoutInflater FC = LayoutInflater。从(登录。这);

最后dialogview = FC。膨胀(。对话框,null);

对话框对话框=新AlertDialog。生成器(登录。这)

settitle(“登录框”)。

setView(dialogview)。

。setpositivebutton(“登录”,新的对话框上。onclicklistener()

{

public void OnClick(DialogInterface arg0,int arg1){

//自动生成方法存根

编辑编辑=(编辑)dialogview findViewById(me);

name_test =编辑字符串。gettext()。tostring();

m_dlog =(显示进度对话框,

“请稍等”、“正在为你登录”,真的);

/ /新thread()

/ {

/ /公共无效run()

/ {

/ /尝试

/ {

/睡眠(3000);

/ }

/ catch(例外E)

/ {

printstacktrace() / E.;

/ }

/ /最后

/ {

/ / m_dlog。dismiss();

/ }

/ }

start() / };

m_dlog。dismiss();

光标CS = MySQL查询(真的,“login_t”,新的字符串[ ] {“用户名”、“名”},“用户名”+“=”+“”+“name_test,零,零,零,零,零);

如果(CS。getcount() > 0)

{

m_dlog。dismiss();

LayoutInflater FC1 = LayoutInflater。从(登录。这);

最后dialogview1 = FC1。膨胀(。题诗,null);

movetofirst() CS;

字符串str = CS GetString(1);

TextView textview1 =(TextView)dialogview1 findViewById(1);

textview1 setText(STR);

对话框DIALOG1 =新AlertDialog。生成器(登录。这)

settitle(“登录框”)。

setView(dialogview1)。

。setpositivebutton(“确定”,新的对话框上。onclicklistener()

{

public void OnClick(DialogInterface arg0,int arg1)

{

意图意图=新intent();

意图。setClass(登录,登录。类);

startActivity(意图);

这finish()登录。;

}

create() });

show() DIALOG1;

}

其他的

{

对话框DIALOG1 =新AlertDialog。生成器(登录。这)

settitle(“信息框”)。

setmessage(“登录失败”)。

。setpositivebutton(“确定”,新的对话框上。onclicklistener()

{

public void OnClick(DialogInterface arg0,int arg1)

{

意图意图=新intent();

意图。setClass(登录,登录。类);

startActivity(意图);

这finish()登录。;

}

create() });

show() DIALOG1;

}

}

})

setnegativebutton(“取消”,

新onclicklistener()对话框上。

{

public void OnClick(DialogInterface arg0,int arg1)

{

这finish()登录。;

}

})

。setneutralbutton(“注册”,新onclicklistener()对话框上。

{

public void OnClick(DialogInterface arg0,int arg1)

{

意图意图=新intent();

意图。setClass(登录。这,zhuceactivity。类);

startActivity(意图);

这finish()登录。;

}

})

create();

show()对话框;

}

}

注册代码:

包;

进口ty;

进口ialog;

进口;

进口ssdialog;

进口interface;

进口;

进口;

进口database;

进口;

进口inflater;

进口;

进口klistener;

进口;

进口xt;

进口ew;

公共课zhuceactivity延伸活动{

*当第一次创建活动时调用。* /

m_dlog进度对话框;

SQLite数据库MySQL;

查看dialogview;

按钮BT1;

按钮BT2;

@Override

public void onCreate(Bundle savedinstancestate){

超级onCreate(savedinstancestate);

setContentView(。市);

BT1 =(按钮)这findViewById(1);

BT2 =(按钮)这findViewById(2);

最后编辑名称=(编辑)这findViewById(1);

最后编辑用户名=(编辑)这findViewById(me);

最后编辑密码=(编辑)这findViewById(rd);

MySQL = openorcreatedatabase(“学生数据库”,mode_private,null);

BT1。setonclicklistener(新onclicklistener() {

public void OnClick(查看arg0){

//自动生成方法存根

如果((name1。gettext()。tostring()。trim()。length() = = 0)| |(用户名。gettext()。tostring()。trim()。length() = = 0)| |(密码。gettext()。tostring()。trim()。length() = = 0))

{

对话框DIALOG1 =新AlertDialog。生成器(zhuceactivity。这)

settitle(“信息框”)。

setmessage(“请输入完整的内容”)。

。setpositivebutton(“确定”,新的对话框上。onclicklistener()

{

public void OnClick(DialogInterface arg0,int arg1)

{ }

create() });

show() DIALOG1;

}

其他的

{

尝试{

光标m_cus = MySQL。rawquery(“选择最大(_id)从login_t”,null);

m_cus。movetofirst();

国际temp_id = m_cus getInt(0)+ 1;

MySQL。execsql(“插入login_t(_id,用户名,姓名,密码)值(“+ temp_id +“,”+用户名。gettext()。tostring()。trim()

+“,”+姓名。gettext()。tostring()。trim() +“,”+密码。gettext()。tostring() trim() +。“)”);

MySQL。();

LayoutInflater FAC2 = LayoutInflater。从(zhuceactivity。这);

查看dialogview2 =因膨胀(,null);

TextView view_1 =(TextView)dialogview2 findViewById(ew1);

view_1。setText(“注册成功!”);

dialog2 =新的警告对话框AlertDialog。生成器(zhuceactivity。这)

settitle(“提示框”)。

setView(dialogview2)。

setpositivebutton(“确定”,

新的对话框上。onclicklistener() {

public void OnClick(DialogInterface arg0,int arg1){

意图意图=新intent();

意图.

( setClass,登录。类);

startActivity(意图);

zhuceactivity。这finish();

}

create() });

dialog2。show();

}

catch(例外E)

{

dialog3 =新对话框AlertDialog。生成器(zhuceactivity。这)

settitle(“信息框”)。

setmessage(“注册失败”)。

。setpositivebutton(“确定”,新的对话框上。onclicklistener()

{

public void OnClick(DialogInterface arg0,int arg1)

{ }

create() });

dialog3。show();

}

}

}

});

setonclicklistener(新onclicklistener() BT2。

{

public void OnClick(视图){

//自动生成方法存根

zhuceactivity。这finish();

}

}

);

}

}

XML的代码字符串:

<?xml version=“1”encoding=“utf-8”?>

<资源>

<字符串>“姓名”姓名/字符串> <

<字符串>“用户名”用户名:< /字符串>

<字符串“密码”>密码:< /字符串>

<字符串>”app_name”登录/字符串> <

<字符串>”app_name1”注册/字符串> <

<字符串> <“成功”登录成功/字符串>

<字符串“BT1”>注册/字符串> <

<字符串“BT2”>取消/字符串> <

<资源>

XML代码对话框:

<?xml version=“1”encoding=“utf-8”?>

< LinearLayout xmlns:Android

=“/apk/res/android”

安卓:layout_width =“fill_parent”

安卓:layout_height =“fill_parent”

Android:方向=垂直

< TextView

安卓:layout_width =“wrap_content”

安卓:layout_height =“wrap_content”

安卓:layout_marginleft =“20dip”

安卓:layout_marginright =“20dip”

Android =重力=“左”

安卓:textappearance =”?安卓:属性/ textappearancemedium”

android:文本=“字符串/用户名”/ >

<编辑

android:id“=用户名/用户名”

安卓:layout_width =“fill_parent”

安卓:layout_height =“wrap_content”

安卓:layout_marginleft =“20dip”

安卓:layout_marginright =“20dip”

安卓:scrollhorizontally =“true”

安卓:“自动图文集”=“假”

Android:大写=“无”

安卓:重力=“fill_horizontal”

安卓:textappearance =”?安卓:属性/ textappearancemedium”/>

< TextView

安卓:layout_width =“wrap_content”

安卓:layout_height =“wrap_content”

安卓:layout_marginleft =“20dip”

安卓:layout_marginright =“20dip”

Android =重力=“左”

安卓:textappearance =”?安卓:属性/ textappearancemedium”

android:文本=“字符串/密码”/ >

<编辑

Android:id =“密码”

安卓:layout_width =“fill_parent”

安卓:layout_height =“wrap_content”

安卓:layout_marginleft =“20dip”

安卓:layout_marginright =“20dip”

安卓:scrollhorizontally =“true”

安卓:“自动图文集”=“假”

Android:大写=“无”

安卓:重力=“fill_horizontal”

安卓:textappearance =”?安卓:属性/ textappearancemedium”/>

< /元素>

Zhuce。XML代码:

<?xml version=“1”encoding=“utf-8”?>

< LinearLayout xmlns:Android

=“/apk/res/android”

安卓:layout_width =“fill_parent”

安卓:layout_height =“fill_parent”

Android:方向=垂直

< TextView

安卓:layout_width =“wrap_content”

安卓:layout_height =“wrap_content”

安卓:layout_marginleft =“20dip”

安卓:layout_marginright =“20dip”

Android =重力=“左”

安卓:textappearance =”?安卓:属性/ textappearancemedium”

安卓:文本=“@字符串/姓名”/>

<编辑

安卓:ID =“”+身份证/姓名”

安卓:layout_width =“fill_parent”

安卓:layout_height =“wrap_content”

安卓:layout_marginleft =“20dip”

安卓:layout_marginright =“20dip”

安卓:scrollhorizontally =“true”

安卓:“自动图文集”=“假”

Android:大写=“无”

安卓:重力=“fill_horizontal”

安卓:textappearance =”?安卓:属性/ textappearancemedium”/>

< TextView

安卓:layout_width =“wrap_content”

安卓:layout_height =“wrap_content”

安卓:layout_marginleft =“20dip”

安卓:layout_marginright =“20dip”

Android =重力=“左”

安卓:textappearance =”?安卓:属性/ textappearancemedium”

android:文本=“字符串/用户名”/ >

<编辑

android:id“=用户名/用户名”

安卓:layout_width =“fill_parent”

安卓:layout_height =“wrap_content”

安卓:layout_marginleft =“20dip”

安卓:layout_marginright =“20dip”

安卓:scrollhorizontally =“true”

安卓:“自动图文集”=“假”

Android:大写=“无”

安卓:重力=“fill_horizontal”

安卓:textappearance =”?安卓:属性/ textappearancemedium”/>

< TextView

安卓:layout_width =“wrap_content”

安卓:layout_height =“wrap_content”

安卓:layout_marginleft =“20dip”

安卓:layout_marginright =“20dip”

Android =重力=“左”

安卓:textappearance =”?安卓:属性/ textappearancemedium”

android:文本=“字符串/密码”/ >

<编辑

Android:id =“密码”

安卓:layout_width =“fill_parent”

安卓:layout_height =“wrap_content”

安卓:layout_marginleft =“20dip”

安卓:layout_marginright =“20dip”

安卓:scrollhorizontally =“true”

安卓:“自动图文集”=“假”

Android:大写=“无”

安卓:重力=“fill_horizontal”

安卓:textappearance =”?安卓:属性/ textappearancemedium”/>

<元素

安卓:layout_width =“fill_parent”

安卓:layout_height =“fill_parent”

Android:方向=“水平”>

<按钮

安卓:ID =“”+身份证/ BT1”

安卓:layout_width =“wrap_content”

安卓:layout_height =“wrap_content”

安卓:layout_marginleft =“20dip”

安卓:layout_marginright =“20dip”

安卓:文本=“@字符串/ BT1”

/>

<按钮

安卓:ID =“”+身份证/ BT2”

安卓:layout_width =“wrap_content”

安卓:layout_height =“wrap_content”

安卓:layout_marginleft =“20dip”

安卓:layout_marginright =“20dip”

安卓:文本=“@字符串/ BT2”

/>

< /元素>

< /元素>

XML的代码为主:

<?xml version=“1”encoding=“utf-8”?>

< LinearLayout xmlns:Android

=“/apk/res/android”

安卓:layout_width =“fill_parent”

安卓:layout_height =“fill_parent”

Android:方向=垂直

< /元素>

XML的代码题诗:

<?xml version=“1”encoding=“utf-8”?>

< LinearLayout xmlns:Android

=“/apk/res/android”

安卓:layout_width =“fill_parent”

安卓:layout_height =“fill_parent”

Android:方向=垂直

< TextView

安卓:ID =“”+身份证/ textview1”

安卓:layout_width =“wrap_content”

安卓:layout_height =“wrap_content”

android:文本=“字符串/成功”/ >

< TextView

安卓:ID =“”+身份证/姓名”

安卓:layout_width =“wrap_content”

安卓:layout_height =“wrap_content”/>

< /元素>

本文标签: 登录字符串代码文本对话框