当我尝试在后台运行功能doTask()时崩溃。我正在尝试使用new Thread(new Runnable(){}),它仅在以下部分有效:
handlerForBar.post(new Runnable(){公共(public)无效run(){doTask();}})
但是当doTask()工作完成时,会显示progressBar。所以我认为AsyncTask可以工作,但是崩溃了。

  public void doTask()
                {

                ListView listView = (ListView)findViewById(R.id.list);

                myArray = new ArrayList<HashMap<String,Object>>();
                HashMap<String, Object> hash_map;

                hash_map = new HashMap<String, Object>();
                hash_map.put(NICK_KEY, "nick");

                myArray.add(hash_map);
                listView.setAdapter(new myListAdapter(myArray,this));
                new myListAdapter(myArray,this).notifyDataSetChanged();
                }



private class myThread extends AsyncTask<String, Void, String> {

          @Override
          protected String doInBackground(String... params) {

              doTask(); //try, catch also FC
            return null;
          }

          ...
         }

* .java的结构:
> public class mainActivity extends Activity{}
>                       public void onCreate()
>                                  new myThread().execute("");
>                       public void doTask()
>                       private class myThread extends AsyncTask<String, Void, String>{}
>                                  protected String doInBackground()
>                                                   doTask()
>                       private class myListView extends BaseAdapter

最佳答案

您无法触摸doInBackground中的UI,而必须使用onProgressUpdateonPostExecute之类的方法来更新UI。参见here

07-24 22:35