私の活動では、Webからビッグデータを取得しています。このデータを取得している間、ユーザーにスピニングホイール付きのProgressDialogを表示したいと思います。このコードをスレッドに入れることでしかできないことですよね?問題は、このデータを取得した後、TableRowsとしてtableLayoutに挿入する必要があり、スレッドからTableLayoutにアクセスできないように見えることです。
この進行状況ダイアログを表示し、スレッドからテーブルレイアウトにアクセスできるようにするにはどうすればよいですか?スレッドの最後で発生するイベントはありますか?
私のコードは次の理由で失敗します:
_tableLayout.addView(_tableRowVar, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
私の完全なコードは:
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();