上一篇为大家分享了关于AsyncTask的使用,本篇结合AsyncTask为大家介绍一个我们经常看到的一个效果,就是当我们点击登录后,会弹出一个请等待的小窗体,这个效果是如何实现的呢?本篇我就带大家简单实现一下。

  首先请看效果图:

  

  就是当我们填写好个人信息后,点击登录,然后就进入了这个界面,好了,下面我们一起来实现一下。

  第一步:布局文件:activity_main.xml

<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="22dp"
android:text="邮箱:" /> <EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/textView1"
android:ems=""
android:inputType="textEmailAddress" /> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_marginTop="40dp"
android:layout_toLeftOf="@+id/editText1"
android:text="密码:" /> <EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_alignLeft="@+id/editText1"
android:ems=""
android:inputType="textPassword" /> <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_marginTop="43dp"
android:layout_toRightOf="@+id/textView2"
android:text="登录" /> <Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_marginLeft="34dp"
android:layout_toRightOf="@+id/button1"
android:text="注册" /> </RelativeLayout>

  第二步:主Activity:

public class MainActivity extends Activity implements OnClickListener{

    private EditText mEditText1;
private EditText mEditText2;
private Button mButton1;
private Button mButton2; private String email;
private String password; private myAsyncTast tast; private ProgressDialog dialog = null; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();//对控件进行初始化
} private void init() {
mEditText1 = (EditText) findViewById(R.id.editText1);
mEditText2 = (EditText) findViewById(R.id.editText2);
mButton1 = (Button) findViewById(R.id.button1);
mButton2 = (Button) findViewById(R.id.button2);
mButton1.setOnClickListener(this);
mButton2.setOnClickListener(this);
} @Override
public void onClick(View arg0) {
switch (arg0.getId()) {
case R.id.button1:
getEditTextValue();//获得用户的输入
tast = new myAsyncTast();//创建AsyncTask
tast.execute();//启动AsyncTask
break; case R.id.button2:
Toast.makeText(MainActivity.this, "注册", Toast.LENGTH_SHORT).show();
break;
}
} private void getEditTextValue() {
email = mEditText1.getText().toString();
password = mEditText2.getText().toString();
} class myAsyncTast extends AsyncTask<Void, Integer, Void>{ @Override
protected void onPreExecute() {
super.onPreExecute();
dialog = ProgressDialog.show(MainActivity.this, "登录提示", "正在登录,请稍等...", false);//创建ProgressDialog
} @Override
protected Void doInBackground(Void... arg0) { Http http = new Http();
int n = http.send(email, password);//发送给服务器
publishProgress(n);
return null; } @Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
dialog.dismiss();//关闭ProgressDialog
if(values[]==){
Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(MainActivity.this, "登录失败", Toast.LENGTH_SHORT).show();
} } } }

  第三步:服务器端(简单起见,仅仅是模拟)

/*
* 模拟服务器端
*/
public class Http {
private int n = ;
public int send(String email, String password){ try {
Thread.sleep();//模拟网络加载
} catch (InterruptedException e) {
e.printStackTrace();
}
if(email.equals("1@qq.com")&&password.equals("")){
n=;
} return n;
} }

  在这里需要说明的时,当我们真正开发时,需要向服务器发送数据时,我们需要在:AndroidManifest.xml文件中声明访问网络权限。

  对于上面的内容,AsyncTask上一篇已经为大家进行了详细的介绍,如果看本篇博客你赶脚有些吃力,请仔细研究一下上一篇的博客,这里就不再赘述,对于ProgressDialog本人也是初次使用,不过可以为大家推荐一篇博客:http://blog.csdn.net/caesardadi/article/details/11982721,这里介绍的非常的详细,有兴趣的童鞋可以好好研究一下。

Android登录等待效果的更多相关文章

  1. Android 仿 窗帘效果 和 登录界面拖动效果 (Scroller类的应用) 附 2个DEMO及源码

    在android学习中,动作交互是软件中重要的一部分,其中的Scroller就是提供了拖动效果的类,在网上,比如说一些Launcher实现滑屏都可以通过这个类去实现.下面要说的就是上次Scroller ...

  2. Android 仿 窗帘效果 和 登录界面拖动效果 (Scroller类的应用) 附 2个DEMO及源代码

    在android学习中,动作交互是软件中重要的一部分.当中的Scroller就是提供了拖动效果的类,在网上.比方说一些Launcher实现滑屏都能够通过这个类去实现.以下要说的就是上次Scroller ...

  3. 易Android登录Demo

    上一页介绍Android项目简单的页面跳转实例,算是对开发环境的熟悉,这一篇将在此基础上增加一些简单的逻辑,实现登录的效果. 登录之前: 登录成功: watermark/2/text/aHR0cDov ...

  4. 【Android源代码下载】收集整理android界面UI效果源码

    在Android开发中,Android界面UI效果设计一直都是很多童鞋关注的问题,今天给大家分享下大神收集整理的多个android界面UI效果,都是源码,都是干货,贡献给各位网友! 话不多说,直接上效 ...

  5. C#.Net网页加载等待效果漂亮并且简单

    最近网页加载数据比较多,点击后给用户就是白板很不友好,想了很久找了些资料,在网页加载中显示等待画面给客户,页面加载完成自动隐藏等待效果. 在网页后台cs代码:    protected void Pa ...

  6. WPF 实现的等待效果界面

    这个界面的效果是从WinForm 转变过来,可以实现等待的效果,操作完成以后就自动关掉. 效果图如下 有一个动态的手机等待效果的样式,中间的文字可以自己定义,提供了方法可以修改中间"正在加载 ...

  7. JQuery+CSS3实现封装弹出登录框效果

    原文:JQuery+CSS3实现封装弹出登录框效果 上次发了一篇使用Javascript来实现弹出层的效果,这次刚好用了JQuery来实现,所以顺便记录一下: 因为这次使用了Bootstrap来做一个 ...

  8. 手机站全局的html+css加载等待效果

    本文只提供思路,CSS神马的自己定制吧,JS是可以优化的,比如,输出图片的JS也可以放到showdiv()里面,我没有做优化,只是实现,别笑话我,我比较懒... 基本思路:由于Html的解析是从上到下 ...

  9. js加载等待效果

    demo01: 加载首页的时候,可能会很缓慢,放一张等待图片. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ...

随机推荐

  1. windows IIS6 PHP搭建

    windows下搭建PHP环境有很多种方法.传说,FastCGI下运行PHP  是 兼顾安全和效率的一种.传说.传说.下面讲解在windows server2003 IIS6中安装 PHP 以下文字, ...

  2. jdk1.6 webService 客户端代码生成和测试

    参数:测试webService的地址:http://10.113.11.1:9090/enocpService/buildingEngService?wsdl 1,eclipse中新建一个项目, 2, ...

  3. RHEL6.5 删除桌面启动器(计算机/Home/回收站)

    首先,安装gconf-editor以获得gconftool-2命令 终端命令: gconftool-2 --set /apps/nautilus/desktop/computer_icon_visib ...

  4. nginx 配置rewrite 笔记

    nginx 配置rewrite笔记: 通过下面的示例来说明一下,1. 先说说location : location 表示匹配传入的url地址,其中配置符有多种,各种情况的意义不一样: location ...

  5. Unity3d中Update()方法的替身

    在网上看到一些资料说Unity3d的Update方法是如何如何不好,影响性能.作为一个菜鸟,之前我还觉得挺好用的,完全没用什么影响性能的问题存在.现在发现确实有很大的问题,我习惯把一大堆检测判断放在U ...

  6. redis持久化以及主从服务器的配置

    作者:silenceper 日期:2013-10-03 原文地址:http://silenceper.com/archives/959.html redis 与memcached 最大的一个区别就是R ...

  7. 练习1-16:修改打印最长文本行的程序的主程序main,使之可以打印任意长度的输入行的长度,并尽可能多地打印文本(C程序设计语言 第2版)

    该书英文配套答案 Answer to Exercise -, page Revise the main routine of the longest-line program so it will c ...

  8. ABP框架详解(五)Navigation

    ABP框架中的Navigation功能用于管理业务系统中所有可用的菜单导航控件,通常在业务系统的首页会有一个全局性的导航菜单,JD商城,天猫,猪八戒网莫不如是.所以为方便起见,Navigation功能 ...

  9. Replication的犄角旮旯(五)--关于复制identity列

    <Replication的犄角旮旯>系列导读 Replication的犄角旮旯(一)--变更订阅端表名的应用场景 Replication的犄角旮旯(二)--寻找订阅端丢失的记录 Repli ...

  10. 开始VS 2012 中LightSwitch系列的第2部分:感受关爱——定义数据关系

    [原文发表地址]  Beginning LightSwitch in VS 2012 Part 2: Feel the Love - Defining Data Relationships [原文发表 ...