0

I know that I can set the layout for a screen to be a progressBar as long as I inflate the layout after all my content has loaded. Is there any way to set a progressBar to wait until a TextView has loaded? For example, if I need to grab some content from my database and as I grab the content, I'd like to show a progressBar in place of that TextView. I was thinking I could try to wrap every TextView that needs this progressBar in a RelativeLayout and just set the visibility whenever the call from the database is finished. Is there a better way to do this? Any help would be appreciated. Thanks!

user1871869
  • 3,317
  • 13
  • 56
  • 106
  • Query your database in AsyncTask, make progressbar visible in onPreExecute() & fill yout textview in onPostExecute() where you can hide your progressbar – Divyang Panchal Sep 24 '16 at 08:26

2 Answers2

1

You can use Aysnc task to fetch data and make progress bar visible before fetching the data and hide it in onPostExecute method of async task. refer this question How to use AsyncTask to show a ProgressDialog while doing background work in Android?

Community
  • 1
  • 1
Pallav Grover
  • 55
  • 2
  • 8
0

As Pallav mentioned the use of Async task can accomplish what you want.Check how to create an Async task and in these methods show/hide progressBar dialog.

@Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();  

        //showDialog() here;
    }

    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub

        //do what you want here//
    }

    @Override
    protected void onPostExecute(Void result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);

        //dismissDialog() here;//


    }
A.J
  • 726
  • 1
  • 7
  • 19