views:

15

answers:

1

Hi all, On my activity, im getting some big data from web, and while getting this data i want to show the user a ProgressDialog with spinning wheel. That i can do only with putting this code into a thread, right ? the problem is that after im getting this data i need to insert it into my tableLayout as TableRows and it seems impossible to access the TableLayout from the thread.

What can i do to show this progress dialog and to be able access the table layout from the thread ?? Is there any event that happens on the end of the thread ?

My code fails for :

_tableLayout.addView(_tableRowVar, new TableLayout.LayoutParams(
      LayoutParams.FILL_PARENT,
      LayoutParams.FILL_PARENT));

My full code is :

final ProgressDialog dialog = ProgressDialog.show(MyActivity.this, "", 
            "Getting data.\nPlease wait...",true);

new Thread() 
{
    public void run() 
    {
        try
        {
            TableLayout _tableLayout;
            _tableLayout = (TableLayout)MyActivity.this.findViewById(R.id.tableLayoutID);

            List<String> data = getDataFromWeb();

            // Get the data and bind it into the table
            publishTableLayoutWithTableRows(_tableLayout, data );

        }
        catch (Exception e) {
            new AlertDialog.Builder(MyActivity.this)
                 .setMessage(e.getMessage())
             .show();
        }
        dialog.dismiss();
    }
}.start();
A: 

You should use AsyncTask

you will also notice comments can use UI thread here next to the methods where you can use UI.

Pentium10
Works great !!!
Shaulian