调用NotifyDataSetChanged()后ListView不更新

时间:2016-12-25 08:07:20

标签: android listview android-asynctask

这是我的活动(pActivity5) -

    BackgroundWorker backgroundWorker=new BackgroundWorker(pActivity5.this,this);
    backgroundWorker.execute(type,str1);

    arrayList1.clear();
    arrayList2.clear();

    sharedPreferences=getSharedPreferences("p_name_tech_1",MODE_PRIVATE);

    int a=sharedPreferences.getInt("s_o_a",0);

    for(int i=0;i<a;i++){
        arrayList1.add(i,sharedPreferences.getString(""+i,"null"));
    }
    for(int i=a;i<(a*2);i++){
        arrayList2.add((i-a),sharedPreferences.getString(""+i,"null"));
    }

    adapter=new Adapter(this,arrayList1,arrayList2);
    adapter.notifyDataSetChanged();
    lv1.setAdapter(adapter);

这是我在BackgroundWorker类中的onPostExecute方法 -

        intent = new Intent(context, pActivity5.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(intent);

当我使用backgroundWorker.execute(type,str1)时.get();然后它工作正常,但这击败了AsyncTask的目的。 所以我想在完成时使用AsyncTask并更新我的ListView。

我甚至试过这个 - How to get the result of OnPostExecute() to main activity because AsyncTask is a separate class? 但没有成功。

0 个答案:

没有答案
相关问题