본문 바로가기

안드로이드

ListView did not receive a notification 오류 해결법

반응형

-  The content of the adapter has changed but ListView did not receive a notification 

     오랬동안 괴롭히던 에러였는데 해결법은 아래와같다.



ArrayList<NfcInfo> nfcList = new ArrayList<NfcInfo>();

ArrayList<NfcInfo> tempList = new ArrayList<NfcInfo>();


private class dbselectTask extends AsyncTask<Void, Void, Void> {



ProgressDialog loagindDialog;


@Override

protected void onPreExecute() {

super.onPreExecute();

loagindDialog = ProgressDialog.show(WriteListActivity.this, "",

"잠시만 기다려 주세요.", true);

}


@Override

protected Void doInBackground(Void... params) {

tempList.clear();

          tempList.add(.......);


return null;

}


protected void onPostExecute(Void result) {

loagindDialog.dismiss();


   nfcList.addAll(tempList);

GoodsAdapter ListView le_list = (ListView) findViewById(R.id.le_list);


mAdapter = new GoodsAdapter(WriteListActivity.this,

R.layout.listview_write, nfcList); //


le_list.setAdapter(mAdapter); // 리스트뷰를 Adapter에 연결한다

}

}


-> 리스뷰에 데이터가 변경되었을때 arrayList를 clear 해주는 타이밍이 문제였던것 같다. 

-> 사용하고 있는 arrayList 와 똑같은  temp arrayList를 만들어준다

-> 바뀐 데이터는  temp arrayList 에 clear , add해준다.

-> 백그라운드 작업이 끝났을때  사용하고 있는 arrayList에 temp를 넣어준다

    ex) nfcList.addAll(tempList)



성공하시길 빕니다!

반응형

'안드로이드' 카테고리의 다른 글

현재 위도 경도를 주소로 변환  (0) 2015.01.06
android nfc url read/write  (0) 2014.12.30
Seekbar 볼륨 조절 AlertDialog 이용  (0) 2014.10.08
Android GCM JSP 연동 예제 (2)  (1) 2014.08.20
Android GCM JSP 연동 예제 (1)  (0) 2014.08.19