日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

android控件ems,Android登录等待效果

發(fā)布時間:2025/4/16 Android 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android控件ems,Android登录等待效果 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

上一篇為大家分享了關(guān)于AsyncTask的使用,本篇結(jié)合AsyncTask為大家介紹一個我們經(jīng)常看到的一個效果,就是當(dāng)我們點擊登錄后,會彈出一個請等待的小窗體,這個效果是如何實現(xiàn)的呢?本篇我就帶大家簡單實現(xiàn)一下。

首先請看效果圖:

就是當(dāng)我們填寫好個人信息后,點擊登錄,然后就進(jìn)入了這個界面,好了,下面我們一起來實現(xiàn)一下。

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

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="郵箱:" />

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="10"android:inputType="textEmailAddress" />

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="密碼:" />

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="10"android:inputType="textPassword" />

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="登錄" />

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="注冊" />

第二步:主Activity:

public classMainActivity extends Activity implements OnClickListener{privateEditText mEditText1;privateEditText mEditText2;privateButton mButton1;privateButton mButton2;privateString email;privateString password;privatemyAsyncTast tast;private ProgressDialog dialog = null;

@Overrideprotected voidonCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

init();//對控件進(jìn)行初始化

}private voidinit() {

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);

}

@Overridepublic voidonClick(View arg0) {switch(arg0.getId()) {caseR.id.button1:

getEditTextValue();//獲得用戶的輸入

tast = new myAsyncTast();//創(chuàng)建AsyncTask

tast.execute();//啟動AsyncTask

break;caseR.id.button2:

Toast.makeText(MainActivity.this, "注冊", Toast.LENGTH_SHORT).show();break;

}

}private voidgetEditTextValue() {

email=mEditText1.getText().toString();

password=mEditText2.getText().toString();

}class myAsyncTast extends AsyncTask{

@Overrideprotected voidonPreExecute() {

super.onPreExecute();

dialog= ProgressDialog.show(MainActivity.this, "登錄提示", "正在登錄,請稍等...", false);//創(chuàng)建ProgressDialog

}

@OverrideprotectedVoid doInBackground(Void... arg0) {

Http http= newHttp();int n = http.send(email, password);//發(fā)送給服務(wù)器

publishProgress(n);return null;

}

@Overrideprotected voidonProgressUpdate(Integer... values) {

super.onProgressUpdate(values);

dialog.dismiss();//關(guān)閉ProgressDialog

if(values[0]==1){

Toast.makeText(MainActivity.this, "登錄成功", Toast.LENGTH_SHORT).show();

}else{

Toast.makeText(MainActivity.this, "登錄失敗", Toast.LENGTH_SHORT).show();

}

}

}

}

第三步:服務(wù)器端(簡單起見,僅僅是模擬)

/** 模擬服務(wù)器端*/

public classHttp {private int n = 0;public intsend(String email, String password){try{

Thread.sleep(5000);//模擬網(wǎng)絡(luò)加載

} catch(InterruptedException e) {

e.printStackTrace();

}if(email.equals("")&&password.equals("123456")){

n=1;

}returnn;

}

}

在這里需要說明的時,當(dāng)我們真正開發(fā)時,需要向服務(wù)器發(fā)送數(shù)據(jù)時,我們需要在:AndroidManifest.xml文件中聲明訪問網(wǎng)絡(luò)權(quán)限。

對于上面的內(nèi)容,AsyncTask上一篇已經(jīng)為大家進(jìn)行了詳細(xì)的介紹,如果看本篇博客你趕腳有些吃力,請仔細(xì)研究一下上一篇的博客,這里就不再贅述,對于ProgressDialog本人也是初次使用,不過可以為大家推薦一篇博客:http://blog.csdn.net/caesardadi/article/details/11982721,這里介紹的非常的詳細(xì),有興趣的童鞋可以好好研究一下。

原文:http://www.cnblogs.com/AndroidJotting/p/4474793.html

總結(jié)

以上是生活随笔為你收集整理的android控件ems,Android登录等待效果的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。