Reputation: 96
I Created Sample program for custom progress bar. it is working but the problem i'm facing is that the progress bar is not set in the middle of the screen.
I have to show list's View items before that i want to show the Progress bar.
Here my complete code is as follow :-
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<com.wang.avi.AVLoadingIndicatorView
android:layout_width="wrap_content"
android:background="#000"
android:layout_gravity="center"
android:layout_height="wrap_content"
style="@style/AVLoadingIndicatorView.Large"
app:indicatorName="BallPulseIndicator"
android:id="@+id/avi"
/>
<ListView
android:id="@+id/visitor_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
main.java
private AVLoadingIndicatorView avi;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_rorder, container, false);
getActivity().setTitle("Order");
String indicator=getActivity().getIntent().getStringExtra("indicator");
avi= (AVLoadingIndicatorView)view.findViewById(R.id.avi);
avi.setIndicator(indicator);
new DownloadJSON().execute();
return view;
}
private class DownloadJSON extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
avi.show();
// avi.setVisibility(View.VISIBLE);
/*
mProgressDialog = new ProgressDialog(getActivity());
mProgressDialog.setTitle("Please Wait");
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
*/
}
@Override
protected Void doInBackground(Void... args) {
try {
}
@Override
protected void onPostExecute(Void args) {
// mProgressDialog.dismiss();
avi.hide();
}
}
}
Like This I tried But it is not working please help me out from this.
Upvotes: 0
Views: 677
Reputation: 2512
Try using RelativeLayout
as a parent of the ListView
and AVLoadingIndicatorView
, and settings the layout_centerInParent
attribute of AVLoadingIndicatorView
to true :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.wang.avi.AVLoadingIndicatorView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#000"
style="@style/AVLoadingIndicatorView.Large"
app:indicatorName="BallPulseIndicator"
android:id="@+id/avi"/>
<ListView
android:id="@+id/visitor_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
</LinearLayout>
Upvotes: 1
Reputation: 538
Simply You can use the Progress Dialog. Example is given below
ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(getActivity(), "", "Please Wait ", true, false);
}
@Override
protected void onPostExecute(Void result) {
if(progressDialog.isShowing()){
progressDialog.dismiss();
}
}
Upvotes: 0