Android实现登录

时间:2023-01-07 23:26:39
 登录界面布局文件
   
   
 1  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E6E6E6"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_head"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:src="@drawable/ic_launcher11"/>
<LinearLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/iv_head"
android:layout_margin="10dp"
android:background="#FFFFFF"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/rl_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="账号"/>
<EditText
android:id="@+id/et_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/tv_name"
android:background="@null"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#E6E6E6"/>
<RelativeLayout
android:id="@+id/rl_userpsd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TextView
android:id="@+id/tv_psw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="密码"/>
<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/tv_psw"
android:inputType="textPassword"
android:background="@null"/>
</RelativeLayout> </LinearLayout>
<Button
android:id="@+id/btn_login"
android:onClick="student"
android:layout_width="match_parent"
android:layout_height="30dip"
android:layout_below="@+id/layout"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:background="#3C8DC4"
android:text="登录"
android:textColor="#FFFFFF"/>
<Button
android:id="@+id/signUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="注册"
android:layout_marginRight="10dp"
android:background="#E6E6E6"
android:textColor="#000000"
android:layout_marginTop="21dp"
android:layout_centerHorizontal="true"
android:layout_below="@+id/btn_login"
android:layout_alignParentRight="true"/> </RelativeLayout>
 package com.itcast.test03;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject; import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast; public class MainActivity extends Activity {
private EditText et_username;
private EditText et_userPsd; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_username = (EditText)findViewById(R.id.et_number);
et_userPsd = (EditText)findViewById(R.id.et_password);
}
public void student(View view){
String name = et_username.getText().toString();//把EditTextable类型转化为字符串并赋值给name、password
String password = et_userPsd.getText().toString();
if(TextUtils.isEmpty(name)||TextUtils.isEmpty(password)){//判断输入的用户和密码是否有为空的
Toast.makeText(this, "用户名和密码不能为空", 0).show();
Intent intent01 = new Intent(this,StudentMainActivity.class);
startActivity(intent01);
}else{
try{ HttpClient client = new DefaultHttpClient();//获取HettpClient对象
//指定访问地址
String path = "http://10.6.78.213:2016/xampp/sse/index.php/home/Index/server_info";
HttpPost httpPost = new HttpPost(path);//Post方式请求网络
//请求服务器并获取服务器返回的信息
HttpResponse response = client.execute(httpPost);
//获取状态码
int code = response.getStatusLine().getStatusCode();
if(code == 200){
//将输入流转换成字符串
InputStream is = response.getEntity().getContent();
//将字节输入转换成字符输入流
InputStreamReader in = new InputStreamReader(is);
//对字符流对象进行包装
BufferedReader bufferedReader = new BufferedReader(in);
//StringBuilder(String str) 构造一个字符串生成器,并初始化为指定的字符串内容。
StringBuilder builder = new StringBuilder();
for (String s = bufferedReader.readLine(); s != null; s = bufferedReader
.readLine()) {
builder.append(s);
}
Log.i("cat", ">>>>>>" + builder.toString());
String UName;
String UPass;
/*JsonObject 就是常说的 json。是一种重要的数据传输对象。
* 其格式为{"key1":value1,"key2",value2....};key 必须是字符串。
很像map对不对,一个key,一个value。
因为ajax请求不刷新页面,但配合js可以实现局部刷新,因此json常常被用来作为异步请求的返回对象使用。*/
JSONObject jsonObject = new JSONObject(builder.toString());
UName = jsonObject.getString("user_name");
UPass = jsonObject.getString("user_password"); if(UName.equals(name)&&UPass.equals(password))
{
Toast.makeText(this, "用户名密码输入正确", 0).show();
Intent intent = new Intent(this,StudentMainActivity.class);
startActivity(intent);
} else
{
Toast.makeText(this, "用户名密码输入不正确", 0).show();
}
} }catch(Exception e){
e.printStackTrace(); }
}
} }
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#E6E6E6"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"> <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textSize="25sp"
android:textColor="#FFFFFF"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="软件学院的通知和公告" /> </RelativeLayout>
</LinearLayout> <GridView
android:id="@+id/gridView"
android:background="#FFFFFF"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center" >
</GridView> </LinearLayout>

1

 package com.itcast.test03;

 import java.util.ArrayList;
import java.util.HashMap; import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.TextView; public class StudentMainActivity extends Activity {
private GridView gridview;
private GridView gridview1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_student_main);
gridview = (GridView)findViewById(R.id.gridView);
ArrayList<HashMap<String,Object>> lstImageItem = new ArrayList<HashMap<String,Object>>();
for(int i = 0;i<20;i++){
HashMap<String,Object> map = new HashMap<String, Object>();
if(i==1){
map.put("ItemImage", R.drawable.ic_launcher02);
map.put("ItemText", "实践教学管理系统");
lstImageItem.add(map);
}else if(i==2){
map.put("ItemImage", R.drawable.ic_launcher06);
map.put("ItemText", "毕业设计管理系统");
lstImageItem.add(map);
}else if(i==3){
map.put("ItemImage", R.drawable.ic_launcher02);
map.put("ItemText", "开放实验管理系统");
lstImageItem.add(map);
}else if(i==4){
map.put("ItemImage", R.drawable.ic_launcher03);
map.put("ItemText", "实习实训管理系统");
lstImageItem.add(map);
}else if(i==5){
map.put("ItemImage", R.drawable.ic_launcher05);
map.put("ItemText", "班级事务管理系统");
lstImageItem.add(map);
}else if(i==6){
map.put("ItemImage", R.drawable.ic_launcher06);
map.put("ItemText", "综合实践管理系统");
lstImageItem.add(map);
}else if(i==7){
map.put("ItemImage", R.drawable.ic_launcher04);
map.put("ItemText", "其他事物2管理系统");
lstImageItem.add(map);
}else if(i==8){
map.put("ItemImage", R.drawable.ic_launcher08);
map.put("ItemText", "其他事物3管理系统");
lstImageItem.add(map);
}else if(i==9){
map.put("ItemImage", R.drawable.ic_launcher01);
map.put("ItemText", "其他事物4管理系统");
lstImageItem.add(map);
}else if(i==10){
map.put("ItemImage", R.drawable.ic_launcher06);
map.put("ItemText", "毕业设计管理系统");
lstImageItem.add(map);
}else if(i==11){
map.put("ItemImage", R.drawable.ic_launcher02);
map.put("ItemText", "开放实验管理系统");
lstImageItem.add(map);
}else if(i==12){
map.put("ItemImage", R.drawable.ic_launcher03);
map.put("ItemText", "实习实训管理系统");
lstImageItem.add(map);
}else if(i==13){
map.put("ItemImage", R.drawable.ic_launcher05);
map.put("ItemText", "班级事务管理系统");
lstImageItem.add(map);
}else if(i==14){
map.put("ItemImage", R.drawable.ic_launcher06);
map.put("ItemText", "综合实践管理系统");
lstImageItem.add(map);
}else if(i==15){
map.put("ItemImage", R.drawable.ic_launcher04);
map.put("ItemText", "其他事物2管理系统");
lstImageItem.add(map);
}else if(i==15){
map.put("ItemImage", R.drawable.ic_launcher08);
map.put("ItemText", "其他事物3管理系统");
lstImageItem.add(map);
}else if(i==17){
map.put("ItemImage", R.drawable.ic_launcher01);
map.put("ItemText", "其他事物4管理系统");
lstImageItem.add(map);
}
}
SimpleAdapter saImageItems = new SimpleAdapter(this,lstImageItem,R.layout.next_activity_student_main,new String[]{"ItemImage","ItemText"},new int[] {R.id.ItemImage,R.id.ItemText});
gridview.setAdapter(saImageItems);
gridview.setOnItemClickListener(new ItemClickListener()); } class ItemClickListener implements OnItemClickListener{ @Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
HashMap<String, Object> item = (HashMap<String,Object>)arg0.getItemAtPosition(arg2);
setTitle((String)item.get("ItemText")); } }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }
添加访问权限   
<uses-permission android:name="android.permission.INTERNET"/>

Android实现登录Android实现登录Android实现登录


Android实现登录的更多相关文章

  1. Android之登录时密码的保护

    在很多的Android项目中都需要用户登录.注册.这样的话在开发中做好保护用户密码的工作就显得尤为重要.这里我把自己的密码保护方法记录下来. 这是我建了一个保存密码的文件,以便于检查自己保存密码或者上 ...

  2. Android SharedPreferences登录记住密码

    SharedPreferences是Android中存储简单数据的一个工具类.可以想象它是一个小小的Cookie,它通过用键值对的方式把简单 数据类型(boolean.int.float.long和S ...

  3. Android微信登录、分享、支付

    转载需要著名出处: http://blog.csdn.net/lowprofile_coding/article/details/78004224 之前写过微信登录分享支付第一版: http://bl ...

  4. Androidの共享登录之方案研究

    由于最近公司提到了一个需求是,一个应用登录成功了,另一个自动登录. 绞尽脑汁想了好几天,看起来很容易但是想深点就漏洞百出,有的时候代码都写完了测试都成功了突然发现给一个假设就完全失效. 先前几个同事之 ...

  5. egret打包android &plus; android微信登录--小结

    公司用egret做了款游戏,需要打android包,做安卓端的微信登录,于是乎开始了第一安卓上的打包,正的是一脸懵 首先遇到的问题有如下: 1. egret打安卓包时经常运行不起来, 主要是gradl ...

  6. android手机登录时遇到&OpenCurlyDoubleQuote;QQ安全登录发现病毒”解决

    android手机作为开源系统非常容易感染病毒,有时候我们会经常遇到手机QQ登录时检测到app被感染,一般情况是由手机感染病毒所引起的,安装腾讯管家后只能检测病毒和卸载感染病毒的软件,不能清除病毒.解 ...

  7. Android之登录那点事

    随着互联网的高速发展,一个应用为了保护用户的隐私,通常会通过设置用户名+密码的验证方式保证用户隐私的相对安全,我知道一般网站的登录验证,通常会设置一个二维码,通过验证二维码,防止恶意软件通过机械程序, ...

  8. android 第三方登录---新浪微博

    1.AndroidManiFest.xml设置,这里我只是简单的用授权,获取基本信息,所以只用了这一个 <!--微博--> <!-- 必须注册在微博授权,分享微博时候用到 --&gt ...

  9. android线程登录

    主入口代码: package com.tp.soft.app; import java.io.IOException; import java.util.HashMap; import java.ut ...

随机推荐

  1. 浅析天猫H5站点

    前言 我们做前端开发的时候,很有可能会做一个竞品分析,比如我就做过去哪儿.艺龙.同程等与携程的移动站点竞品分析,竞品分析的目的一般是技术对比,但是更多的是业务对比,知己知彼,百战不殆:我们同时会借鉴. ...

  2. 【Swift学习】Swift编程之旅---字符与字符串(五)

    String是swift的字符串类型.一个字符串是一个有效的字符序列,因此还可以使字符集合表示.通过+符号可以连接字符串. String 类型是一种快速.现代化的字符串实现.每一个字符串都是由独立编码 ...

  3. Python之路【第九篇】堡垒机基础&amp&semi;数据库操作

    复习paramiko模块 Python的paramiko模块,是基于SSH用于连接远程服务器并执行相关操作. SSHClient #!/usr/bin/env python #-*- coding:u ...

  4. js上传和预览图片

    [1].[代码] [HTML]代码 跳至 [1] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...

  5. winserve2008下不能运行winXP下开发的应用程序&srarr;更改&OpenCurlyDoubleQuote;兼容性”

    winserve2008下不能运行winXP下开发的应用程序 对策:更该“兼容性”

  6. InetAddress类的使用

    1.1. 简介 IP地址是IP使用的32位(IPv4)或者128位(IPv6)位无符号数字,它是传输层协议TCP,UDP的基础.InetAddress是Java对IP地址的封装,在java.net中有 ...

  7. 用js编解码base64

    以下是编码和解码的方法 function Base64() { // private property _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef ...

  8. 【PAT】B1008 数组元素循环右移问题

    猥琐方法 直接分成两部分输出数组元素,注意空格的问题 #include<stdio.h> int arr[101]; void Priarr(int a,int b){ if(a<= ...

  9. 从零开始学习html(三) 认识标签&lpar;第二部分&rpar;

    一.使用ul,添加新闻信息列表 <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Ty ...

  10. DevExpress WinForms v18&period;2新版亮点(三)

    行业领先的.NET界面控件2018年第二次重大更新——DevExpress v18.2日前正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了DevExpress WinForms v1 ...