notifyDataSetChanged是在ui线程中更新的?
代码贴出来看看。

解决方案 »

  1.   


    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.foundation);
    getapp();//主线程调用了一次

    }public void onRefresh() {
       new AsyncTask<Void, Void, Void>() { @Override
    protected Void doInBackground(Void... params) {
    SystemClock.sleep(1000);
            getapp();//此处线程调用一次 mListView.setVisibility(View.VISIBLE);
            return null;
    }public void getapp() {

              List<AppInfo> appList = new ArrayList<AppInfo>();            for(int i = 0; i < string.length; i++) {
    AppInfo tmpInfo = new AppInfo();
    //此处省略赋值语句
    appList.add(tmpInfo);
    }

    adapter = new ListViewAdapter(this, appList);//

    if (test==0)
    {
    mListView.setAdapter(adapter);
    test=1;
            }
    else
    {
    appList.clear();
    appList.addAll(appList);
    adapter.notifyDataSetChanged();

    } }

      

  2.   

    AsyncTask用法不對,不要在子線程(doInBackground)更新ui
      

  3.   

    你debug看下有没有执行  else
            {
                appList.clear();           
                appList.addAll(appList);           
                adapter.notifyDataSetChanged();
                             
            }
      

  4.   

    是不是应该放在onPostExecute运行
    还有就是debug调试运行到了else哪里,都很正常
      

  5.   

    appList.clear();           
                appList.addAll(appList);           
                adapter.notifyDataSetChanged();
    中clear完后,你得先重新再获取一遍applist,
    List<AppInfo> appList = new ArrayList<AppInfo>();                   for(int i = 0; i < string.length; i++) {
                AppInfo tmpInfo = new AppInfo();
                //此处省略赋值语句
                appList.add(tmpInfo);
    然后再刷新
      

  6.   

    clear只是清除以前的数据,和现在的数据无关