Rox Rox - 10 months ago 58
Android Question

ProgressDialog froze when a table is beeing populated with big amount of data

You shall never work with UI stuff outside the UI thread (main thread). But what to do in this case:

Run a new thread to retrieve a huge load of data. Meanwhile, show a ProgressDialog indicating the work. When the data is retrieved, invoke the main thread and populate the table. When populating the table with the huge load of data, the ProgressDialog is "frozen" for some seconds (since the UI thread is busy with populating the table).

Is there any way to make the ProgressDialog not to "freeze" while the table is beeing populated?

public class MyActivity extends Activity {
private ProgressDialog progressDialog;
private TableLayout tableLayout;

protected void onCreate(Bundle savedInstanceState) {
tableLayout = (TableLayout)v.findViewById(;

progressDialog =, "", "Loading...");
new Thread(new Runnable() {
public void run() {
final List<Data> data = fetchBigDataFromInternet();
MyActivity.runOnUiThread(new Runnable() {
public void run() {
for(Data d : data) { // This makes the progressDialog to freeze
TableRow tableRow = new TableRow(MyActivity.this);

Answer Source

Yes there is a way to make the dialog not to freeze, and thats using the "Lazy Load" technique, if the ammount of data you are populating is huge, break it in smaller parts, and populate accordingly, you need to implement a mechanism to know when new a new "piece" of the data has to be populated, this is very common in apps that have a huge amount of data, usually an "updating" or "refreshing" message is used...

Hope this helps..