Here's my code:
Using java Syntax Highlighting
- package com.nico.ProgressDialogTest;
- import java.util.ArrayList;
- import java.util.List;
- import android.app.ListActivity;
- import android.app.ProgressDialog;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.ArrayAdapter;
- import android.widget.ListView;
- public class ProgressDialogTest extends ListActivity {
- ProgressDialog myProgressDialog = null;
- private List<String> directoryEntries = new ArrayList<String>();
- private ProgressDialog p;
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- directoryEntries.add("Click me");
- directoryEntries.add("Click me too");
- ArrayAdapter<String> directoryList = new ArrayAdapter<String>(
- ProgressDialogTest.this, R.layout.file_row,
- directoryEntries);
- setListAdapter(directoryList);
- }
- private void createList() {
- // TODO Auto-generated method stub
- p = ProgressDialog.show(ProgressDialogTest.this, "Please wait..", "Loading list..", true);
- new Thread(){
- public void run(){
- //do some extreme work before creating list
- try {
- sleep(5000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- directoryEntries.clear();
- directoryEntries.add("Android");
- directoryEntries.add("Developer");
- directoryEntries.add("Challenge");
- p.dismiss();
- }
- }.start();
- ArrayAdapter<String> directoryList = new ArrayAdapter<String>(
- ProgressDialogTest.this, R.layout.file_row,
- directoryEntries);
- setListAdapter(directoryList);
- }
- protected void onListItemClick(ListView l, View v, int position, long id) {
- createList();
- }
- }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
what i want to do is to do something heavy before updating the list, thus i use the ProgressDialog while the work is in progress. But using above code, the list is not updated. I believe the problem is because the method setListAdapter(directoryList) is called before the content of the list updated. The problem is i don't know how to solve this problem
Please help, everyone


.




