以下は機能していない私のコードであり、「ビュー階層を作成した元のスレッドのみがそのビューにアクセスできる」と表示される理由がわかりません。LoadValues()メソッド内でリストビューのアダプタを設定したい場合.. "listView.setAdapter(adapter)"
public class ProgressDialogActivity extends Activity {
private ProgressDialog progressDialog;
private ListView listView;
private ArrayList<String> lstValores;
private Handler progressBarHandler = new Handler();
private int mProgressStatus, mProgressTotal;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lstValores = new ArrayList<String>();
listView = (ListView) findViewById(R.id.listView1);
this.LoadValues();
}//onCreate
public void LoadValues(){
progressDialog = new ProgressDialog(ProgressDialogActivity.this);
progressDialog.setTitle("Aguarde..");
progressDialog.setMessage("Cargando lista..");
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setProgress(0);
progressDialog.show();
new Thread(new Runnable() {
public void run() {
mProgressTotal = (int) 1000;
try {
for (int i = 0; i < mProgressTotal; i++) {
lstValores.add("valor " + i);
mProgressStatus = (int) ((i * 100) / mProgressTotal);
progressBarHandler.post(new Runnable() {
public void run() {
progressDialog.setProgress(mProgressStatus);
}
});
}// end for
ArrayAdapter<String> adapter = new ArrayAdapter<String>(ProgressDialogActivity.this,
R.layout.textviewlist_layout,
lstValores);
listView.setAdapter(adapter);
progressDialog.dismiss();
} catch (Exception e) {
e.printStackTrace();
}
}// end run
}).start();// end Thread
}// end LoadValues
} // Activity