Find TableLeyout in a thread (Because of the ProgressDialog)
Posted
by Shaulian
on Stack Overflow
See other posts from Stack Overflow
or by Shaulian
Published on 2010-06-05T16:47:50Z
Indexed on
2010/06/05
16:52 UTC
Read the original article
Hit count: 427
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();
© Stack Overflow or respective owner