vNext
vNext

Reputation: 1122

Displaying progress dialog before show content

     progressDialog = ProgressDialog.show(MainActivity.this, "", "Loading...");
     Thread thread = new Thread() {

        public void run() {
            latch.countDown();
            try{
                sleep(3000);        
                } 
            catch (Exception e) {       
                Log.e("tag", e.getMessage());       
            }

            progressDialog.dismiss();

        }

    };
    thread.start();   listView.setAdapter(adapter);

I want show loading in 3 seconds then show listview but list always show immediately. How can I want thread finished before showing listview?

Upvotes: 0

Views: 144

Answers (1)

Yevgeny Simkin
Yevgeny Simkin

Reputation: 28379

You shouldn't make people wait for no reason. If you have something to load, load it. Otherwise draw what you can when you can.

As an answer to your specific question you would need to have the Thread setAdapter after it slept for 3 seconds (right now that call is outside the Thread... I think you think that that call blocks, but that's the whole point of the Thread, it does its own thing while the rest of your code executes).

However, Thread can't do anything to your display thread (other than throw an exception) so you'd have to wrap that listView.setAdapter(adapter) call in a Runnable and call it via a Handler from your Thread....

but don't!

Upvotes: 2

Related Questions