0

I have a TabLayout consisting of 6 fragments, controlled by a ViewPager. Its function is to look up a word in one (or more) dictionary onlines, each online dictionary represented by the tab. Once I have the word to look up, I launch multiple DictAsyncTask in parallel via this code:

            dictAsyncTask = new DictAsyncTask(DictionaryLookUp.this, "Tatoeba");
            dictAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

            dictAsyncTask = new DictAsyncTask(DictionaryLookUp.this, "Jukuu");
            dictAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

            dictAsyncTask = new DictAsyncTask(DictionaryLookUp.this, "Weblio");
            dictAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

Up to now, I had a single ProgressBar, but I would prefer to have one ProgressBar per tab header (since some downloads take longer than others).

I found this snippet on SO and it currently is associated with my main RelativeLayout:

            progressBar = new ProgressBar(DictionaryLookUp.this,null,android.R.attr.progressBarStyleHorizontal);

            RelativeLayout rlvDictionaryLookUp = (RelativeLayout) findViewById(R.id.rlvDictionaryLookUp);
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100,100);

            params.addRule(RelativeLayout.CENTER_IN_PARENT);
            rlvDictionaryLookUp.addView(progressBar,params);
            progressBar.setVisibility(View.VISIBLE);

before I paste more code, would it be possible to create e.g. 3 ProgressBar objects and associated them and locate them on top of the corresponding tab header:

enter image description here

Mairyu
  • 809
  • 7
  • 24
  • why not have some sort of parent fragment and add a progress bar to there and the rest of your fragments extends that ? that way inherit the prograss bar in all your fragments. – user456 Mar 01 '18 at 05:00
  • oh, you mean put the ``ProgressBar`` in the xml of the fragments? But that's just a ``ListView`` in my case and not the header of the tablayout. Since I want them on the tab header, I think I have to approach that from the top view where I instantiate the ``TabLayout`` ? – Mairyu Mar 01 '18 at 05:07
  • Ah i thought you wanted to add progressbar to your fragments. In this case you need to add customer view to your tabs. When you executing your asynctask, it should update your custom view in tabs using tablayout.getTabAt(idx) . – user456 Mar 01 '18 at 06:00

0 Answers0