活动呼叫之间的进度活动圈

时间:2013-09-20 12:17:04

标签: android

点击注册进入登录页面。我想在它们之间显示一个Progress Circle。我已经看到堆栈溢出中的示例用AsynTasks解释这个,对于ListView和所有。我想要一个非常简单的示例,通过在加载登录屏幕时单击“注册按钮”来延迟显示它。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="@dimen/layout_padding" >

    <!-- To remove the focus of edit text for the first time -->

    <LinearLayout
        android:layout_width="0px"
        android:layout_height="0px"
        android:focusable="true"
        android:focusableInTouchMode="true" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="@dimen/title_image_height"
        android:layout_marginTop="@dimen/title_image_margin_top"
        android:contentDescription="@string/title"
        android:src="@drawable/site_image" />

    <EditText
        android:id="@+id/editWorkEmail"
        style="@style/text.edit"
        android:layout_centerInParent="true"
        android:layout_marginBottom="@dimen/margin"
        android:hint="@string/hint_work_email"
        android:inputType="textEmailAddress" />

    <Button
        android:id="@+id/buttonSignUp"
        style="@style/button"
        android:layout_width="match_parent"
        android:layout_below="@id/editWorkEmail"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="@dimen/margin"
        android:text="@string/button_sign_up" />

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerInParent="true"
        android:layout_centerVertical="true"
        android:indeterminateDrawable="@drawable/progress" >

    </ProgressBar>

</RelativeLayout>

1 个答案:

答案 0 :(得分:1)

首先,当你开始活动时,我认为它立即开始,不要花太多时间开始不知道你是如何实际工作的。您可以在调用请求时显示进度对话框,并在获得响应后等待响应,只是取消当前进度,如果响应成功,则注册过程然后开始登录

使用AsynTask类可以这样做

private class SignupTask extends AsyncTask<Void,Void,String>{
     private ProgressDialog pDialog;
     public void onPreExecute(){
         pDialog = ProgressDialog.showDialog(context,"Signup Process","Please wait");
     }
     public String doInBackground(Void... params){
         // here call your web call process and send appropriate message as return
     }
     public void onPostExecute(String result){
         // here get the result do action
         pDialog.dismiss();
     }
}

创建此类的对象并执行new SignupTask().execute();

相关问题