I would like to add to my main layout a progressbar with visibility = GONE at the beginning.
After a user click a serverrequest will be sent and handle in asynctask. In that time, progressbar should be visible and staying over my main layout.
I tried to do this using merge-layout.
The main problem is, that it's still possible to edit ui-elements and click the buttons. Is it possible to prevent this behaviour?
Maybe there are some layout propertiers i don't know about?
progressbar.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/waiting_dialog"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="@color/transparent_grey">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
main_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_width="fill_parent">
<LinearLayout
android:id="@+id/ticket_reg_linear_inner"
android:layout_height="fill_parent"
android:background="@drawable/bg_main"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="10dp"
android:orientation="vertical"
android:layout_width="fill_parent">
<EditText
android:id="@+id/ticket_reg_phone_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:text="@string/text_491"
android:maxLines="1" android:singleLine="true" android:imeOptions="actionDone"/>
<Button
android:id="@+id/ticket_reg_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="15dp"
android:layout_marginLeft="10d开发者_开发技巧p"
android:text="@string/text_activate"/>
</LinearLayout>
</ScrollView>
<include layout="@layout/waiting_dialog"/>
</merge>
For this kind of thing it would be better to create a ProgressDialog that will mask your Activity. You create it in onCreateDialog()
and show it with showDialog()
before your start the task, and dismiss it once the task completes with dismissDialog()
in onPostExecute()
of AsyncTask.
ProgressDialog progressDialog = new ProgressDialog(mContext);
progressDialog.setTitle("Loading");
progressDialog.setMessage("Please Wait...");
progressDialog.setCancelable(false);
You can add a progress bar into the main xml file where you need it and in the main class file you can set the progressbar's to Visibility as you desire.To first make the progressbar invisible, in the oncreate method set the progressbar property like this
progressbar = (ProgressBar) findViewById(R.id.myprogressBar);
progressbar.setVisibility(View.INVISIBLE);
Then you can make the progress bar visible inside the onClickListener or whereever you want the progressbar to be visible,
progressbar.setVisibility(View.VISIBLE);
progressbar.setProgress(0);
And finally you can set the visibility to View.GONE
on completion of the process.
Another option will be using a progressDialog...
private ProgressDialog dialog;
dialog = new ProgressDialog(MyApp.this);
dialog.setTitle("this is my ProgressBar");
dialog.setIcon(R.drawable.icon);
dialog.setMessage("Loading...");
dialog.setIndeterminate(true);
dialog.setCancelable(true);
dialog.show();
精彩评论