android实现登录注册Word格式.docx
- 文档编号:19692856
- 上传时间:2023-01-08
- 格式:DOCX
- 页数:21
- 大小:20.49KB
android实现登录注册Word格式.docx
《android实现登录注册Word格式.docx》由会员分享,可在线阅读,更多相关《android实现登录注册Word格式.docx(21页珍藏版)》请在冰豆网上搜索。
loginButton.setOnClickListener(b1);
registerButton=(Button)findViewById(R.id.btn_Reset);
registerButton.setOnClickListener(b1);
username=(EditText)findViewById(R.id.et_staff_no);
password=(EditText)findViewById(R.id.et_password);
OutButton=(Button)findViewById(R.id.btn_Out);
OutButton.setOnClickListener(newView.OnClickListener(){
@Override
publicvoidonClick(Viewv){
builder.setTitle("
确定退出?
”);
builder.setNegativeButton("
确定"
newandroid.content.DialogInterface.OnClickListener(){
@Override
publicvoidonClick(DialogInterfacedialog,intwhich){
//TODOAuto-generatedmethodstub
dialog.dismiss();
}
});
builder.setPositiveButton("
退出"
newandroid.content.DialogInterface.OnClickListener(){
ExitAll.getInstance().exit();
builder.create().getWindow().setGravity(Gravity.BOTTOM);
builder.show();
}
});
builder=newAlertDialog.Builder(this);
}
publicclassButtonListenerimplementsView.OnClickListener{
publicbooleanlogin(Stringstr1,Stringstr2){
booleanb=false;
Stringss=IPAddress.IP+"
Login?
username="
+str1+"
&
password="
+str2;
URLurl=null;
HttpURLConnectionconn=null;
try{
url=newURL(ss);
}catch(MalformedURLExceptione){
e.printStackTrace();
}
conn=(HttpURLConnection)(url.openConnection());
}catch(IOExceptione){
InputStreamis=null;
is=conn.getInputStream();
BufferedReaderin=newBufferedReader(newInputStreamReader(is));
Stringline;
while((line=in.readLine())!
=null){
if(line.equals("
true"
)){
b=true;
}
is.close();
}catch(IOExceptione){
}
conn.disconnect();
returnb;
}
publicvoidonClick(Viewview){
if(view==loginButton){
if((username.getText().toString()).equals("
)||(password.getText().toString()).equals("
Toast.makeText(getApplicationContext(),"
用户名或密码不可为空"
Toast.LENGTH_SHORT).show();
return;
if(login(username.getText().toString(),password.getText().toString())){
IPAddress.StaffNo=username.getText().toString();
s=username.getText().toString();
intent=newIntent();
Toast.makeText(LoginActivity.this,"
登录成功"
+info,Toast.LENGTH_SHORT).show();
intent.setClass(LoginActivity.this,MainActivtity.class);
startActivity(intent);
//IPAddress.username=s;
gol.setLoginName(s);
password.setText("
);
}
else{
Toast.makeText(LoginActivity.this,"
用户名或密码错误"
elseif(view==registerButton){
intent=newIntent();
intent.setClass(LoginActivity.this,RegisterActivity.class);
startActivity(intent);
}
Xml布局:
<
?
xmlversion="
1.0"
encoding="
utf-8"
>
LinearLayout
xmlns:
android="
android:
orientation="
vertical"
gravity="
center_horizontal"
layout_width="
fill_parent"
layout_height="
fill_parent”>
<
android:
horizontal"
paddingTop="
35px"
layout_gravity="
wrap_content"
>
<
TextView
android:
text="
用户名"
textSize="
20sp"
100sp"
center_vertical"
textColor="
#000000"
/>
EditText
id="
@+id/et_staff_no"
singleLine="
0"
200sp"
/>
/LinearLayout>
密码"
@+id/et_password"
<
Button
@+id/btn_Login"
80dp"
登录"
18sp"
@+id/btn_Reset"
注册"
@+id/btn_Out"
退出”
注册界面:
publicclassRegisterActivityextendsActivity{
privateEditTextetv1,etv2,etv3,etv4,etv5,etv6,etv7,etv8;
privateButtonb1=null,b2=null;
privatePersonuser=newPerson();
//TODOAuto-generatedmethodstub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.register);
ExitAll.getInstance().addActivity(this);
etv1=(EditText)this.findViewById(R.id.reset_name);
etv2=(EditText)this.findViewById(R.id.reset_password);
etv3=(EditText)this.findViewById(R.id.reset_mail);
etv4=(EditText)this.findViewById(R.id.reset_telephone);
etv5=(EditText)this.findViewById(R.id.reset_xing);
etv6=(EditText)this.findViewById(R.id.reset_ming);
etv7=(EditText)this.findViewById(R.id.reset_colleage);
etv8=(EditText)this.findViewById(R.id.reset_address);
b1=(Button)findViewById(R.id.btn_command);
b2=(Button)findViewById(R.id.btn_cback);
b1.setOnClickListener(newView.OnClickListener(){
@Override
publicvoidonClick(Viewv){
//TODOAuto-generatedmethodstub
if((etv1.getText().toString()).equals("
)||(etv2.getText().toString()).equals("
请填完信息"
Toast.LENGTH_LONG).show();
return;
sendData();
});
b2.setOnClickListener(newView.OnClickListener(){
Intentintent=newIntent();
intent.setClass(getApplicationContext(),LoginActivity.class);
startActivity(intent);
privatevoidgetData(){
try{
user.setusername(URLEncoder.encode(etv1.getText().toString(),"
gb2312"
));
//发送人姓名
user.setpassword(URLEncoder.encode(etv2.getText().toString(),"
user.setStu_email(URLEncoder.encode(etv3.getText().toString(),"
user.setStu_tel(URLEncoder.encode(etv4.getText().toString(),"
user.setStu_fname(URLEncoder.encode(etv5.getText().toString(),"
user.setStu_lname(URLEncoder.encode(etv6.getText().toString(),"
user.setStu_Department(URLEncoder.encode(etv7.getText().toString(),"
user.setStu_address(URLEncoder.encode(etv8.getText().toString(),"
}catch(UnsupportedEncodingExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
privatevoidsendData(){
getData();
Stringss=IPAddress.IP+"
ResetServlet"
URLurl=null;
HttpURLConnectionconn=null;
booleanbb=true;
try{
url=newURL(ss);
}catch(MalformedURLExceptione){
conn=(HttpURLConnection)(url.openConnection());
}catch(IOExceptione){
ClientChangTypecc=newClientChangType();
cc.ObjectToXML(user,bean.Person.class,conn);
if(conn.getResponseCode()!
=200){
Toast.makeText(getApplicationContext(),"
请求url失败"
thrownewRuntimeException("
InputStreamis=conn.getInputStream();
//获取返回数据
BufferedReaderbf=newBufferedReader(newInputStreamReader(is));
Stringline="
while((line=bf.readLine())!
=null){
if("
false"
.equals(line))
bb=false;
is.close();
}catch(IOExceptione){
bb=false;
}
conn.disconnect();
if(bb){
Intentintent=newIntent();
Toast.makeText(getApplicationContext(),"
申请成功!
intent.setClass(RegisterActivity.this,LoginActivity.class);
//登录成功跳转到主功能界面
//启动Activity
else
注册失败!
UTF-8"
center_horizontal
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- android 实现 登录 注册