Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 调用NotifyDataSetChanged()后ListView未更新_Android_Listview_Android Asynctask - Fatal编程技术网

Android 调用NotifyDataSetChanged()后ListView未更新

Android 调用NotifyDataSetChanged()后ListView未更新,android,listview,android-asynctask,Android,Listview,Android Asynctask,这是我的活动(pActivity5)- 当我使用backgroundWorker.execute(type,str1.get())时;然后,它工作得很好,但这违背了异步任务的目的。 因此,我想使用AsyncTask并在它完成时更新我的ListView 我甚至试过这个- 但是没有成功。为什么不使用lv1.setAdapter(适配器)在onPostExecute中?@ρцσѕρєK,因为两者处于不同的位置Class@AvinashSaran您在帖子中提到的SO线程中的解决方案有什么问题?@avin

这是我的活动(pActivity5)-

当我使用backgroundWorker.execute(type,str1.get())时;然后,它工作得很好,但这违背了异步任务的目的。 因此,我想使用AsyncTask并在它完成时更新我的ListView

我甚至试过这个-
但是没有成功。

为什么不使用
lv1.setAdapter(适配器)
onPostExecute
中?@ρцσѕρєK,因为两者处于不同的位置Class@AvinashSaran您在帖子中提到的SO线程中的解决方案有什么问题?@avinasharan:pass lv1 to backgroundWorkerclass@AvinashSaran在onPostExecute中创建一个回调,将其发送到pActivity5,然后更新listview
    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);
        intent = new Intent(context, pActivity5.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(intent);