ProgressBar not showing
Asked Answered
T

5

7

My Relative layout has two child Rcyclerview (Invisible) and progressbar .

What i want is : Oncreate of layout , recyclerview to invisible and progress bar to show until AsyncTask(getting images from SD folder) completes and recyclerview visible and progressbar invisible .

What Happening is : My app not showing progressbar . And after asyctask completes , my recyclerview shows up .

XML :

 <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/view3">

                <android.support.v7.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingTop="5dp"
                    android:divider="@null"
                    android:visibility="invisible"
                    android:id="@+id/recycler_view_cameragallery"
                    android:dividerHeight="0dp"
                    android:fadingEdge="none" />

                <ProgressBar
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/progressBar_Gallery"
                    style="?android:attr/progressBarStyleLarge"
                    android:layout_centerInParent="true"
                    android:layout_gravity="center"
                    android:padding="12dp" />
            </RelativeLayout>

ActivityCode:

public View onCreateView(LayoutInflater inflater,@Nullable ViewGroup container,@Nullable Bundle savedInstanceState){

        View rootView=inflater.inflate(R.layout.camera_layout,container,false);
        rootView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        ButterKnife.inject(this,rootView);
        init();
        initialise(rootView);
        initialiseListeners();
        listofImagesPath = new ArrayList<String>();
        new mediaScanAyscTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);}

AsyncTask

public class mediaScanAyscTask extends AsyncTask<Void,Void,Void>{

        @Override
        protected Void doInBackground(Void... params) {

            return null;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            adapter.clearApplications();
            galleryProgressBar.setVisibility(View.VISIBLE);
            galleryProgressBar.getIndeterminateDrawable().setColorFilter(Color.parseColor("#ff4081"), PorterDuff.Mode.MULTIPLY);
            cameraRecyclerView.setVisibility(View.INVISIBLE);

        }

        @Override
        protected void onPostExecute(Void aVoid) {
            listofImagesPath = RetriveCapturedImagePath();

            if(listofImagesPath!=null){
                adapter.addApplications(listofImagesPath);
            }
            galleryProgressBar.setVisibility(View.INVISIBLE);
            cameraRecyclerView.setVisibility(View.VISIBLE);
            super.onPostExecute(aVoid);
        }
    }

Please help me by highlighting where i got wrong .

Tetrahedral answered 17/5, 2016 at 10:17 Comment(4)
Try changing recycler view visiblity to gone instead of invisibleCambodia
@ShashankUdupa : No , still not workingTetrahedral
I think the progressbar is too small to see, try removing the padding="12dp" from ProgressBarCambodia
@ShashankUdupa : No this too not working . Whats happening is : this async task runs two times . 1 . oncreate and 2. On ActivityResult method of camera click . So what happening is after a click , screen goes black until all postExecution gets done .Tetrahedral
L
15

In my case, the emulator had the Animations turned OFF in the Developer Mode and so I could not see the progress bar.

Lucchesi answered 15/4, 2017 at 21:0 Comment(1)
You are a lifesaver!Leboeuf
A
1

Make your layout gone rather than invisable

Ability answered 17/5, 2016 at 10:23 Comment(1)
@Tetrahedral in android.support.v7.widget.RecyclerView set visibility to gone not invisible , Do not change visibility of ProgressBar in your xml fileAbility
U
0

I hope this answer will help you.

@Override
protected void onPostExecute(Void aVoid) {
    listofImagesPath = RetriveCapturedImagePath();
        if(listofImagesPath!=null){
            adapter.addApplications(listofImagesPath);
        }
    galleryProgressBar.setVisibility(View.GONE);
    cameraRecyclerView.setVisibility(View.VISIBLE);
    super.onPostExecute(aVoid);
}

Second option is remove your ProgressBar from .xml file and create programmatically.

class YourClassName extends AsyncTask<String, Void, Boolean>{
    ProgressDialog dialog;  

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        dialog = new ProgressDialog(Detail_Activity.this);
        dialog.setTitle("your title");
        dialog.setMessage("your message");
        dialog.setCancelable(false);
        dialog.show();
    }

    @Override
    protected Boolean doInBackground(String... params) {
        return null;
    }

    @Override
    protected void onPostExecute(Boolean aBoolean) {
        super.onPostExecute(aBoolean);
        dialog.cancel();
    }
}
Undenominational answered 17/5, 2016 at 10:35 Comment(3)
Try this second code which is i mention above. it will help you.Undenominational
No still not working . What happening is : in debugging its showing Progressbar but when i run normally its still jot showingTetrahedral
can you upload screenshots. it help full to understand exact problemUndenominational
C
0

I had the same problem the reason is the ProgressBar goes to the bottom of RecyclerView. You need to wrap your RecyclerView and ProgressBar in to a FrameLayout.

<RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/view3">
         <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <android.support.v7.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingTop="5dp"
                    android:divider="@null"
                    android:visibility="invisible"
                    android:id="@+id/recycler_view_cameragallery"
                    android:dividerHeight="0dp"
                    android:fadingEdge="none" />

                <ProgressBar
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/progressBar_Gallery"
                    style="?android:attr/progressBarStyleLarge"
                    android:layout_centerInParent="true"
                    android:layout_gravity="center"
                    android:padding="12dp" />
        </FrameLayout>
  </RelativeLayout>
Cystolith answered 25/9, 2017 at 10:33 Comment(0)
W
-1
Try this
<ProgressBar
    style="@android:style/Widget.ProgressBar.Horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:progress="100"
    android:id="@+id/progress"/>
Want answered 17/5, 2016 at 12:24 Comment(5)
explain your answer so user will get more clarity on itVannie
this attribute style=?android:attr/progressBarStyleLarge give programmers limited control of the progressBar to have full control of the progressBar like android:progress="100" you new to use this attribute style="@android:style/Widget.ProgressBar.Horizontal"Want
Please note that comments are temporary and could be deleted anytime. If you have additional information to provide, please update your answer by clicking on the "edit" link under the post. Thank you.Axial
Thanks. I will take note of that.Want
or style="?android:progressBarStyleHorizontal"Highcolored

© 2022 - 2024 — McMap. All rights reserved.