2013-07-22 1 views
1

ListActivty에 대한 사용자 정의 기본 어댑터가 있습니다.어댑터 notifyDataSetChanged는 postDelayed 일 때만 작동합니다.

@Override 
protected void onListItemClick(ListView listView, View view, int position, long id) { 
    String pkg = mAdapter.getItem(position).toString(); 
    boolean isProtected = ApplicationUtils.isPackageProtected(this, pkg) != null; 
    PreferenceUtils.setPreference(mContext, null, pkg, !isProtected, false); 
    mAdapter.notifyDataSetChanged(); 
} 

그러나, notifyDataSetChanged 목록보기를 업데이트하지 않습니다 내가 어떤 항목을 클릭 한 후 목록을 업데이트하기 위해 노력하고있어,이 내 onListItemClick 코드입니다. 해결 방법으로 foor

@Override 
protected void onListItemClick(ListView listView, View view, int position, long id) { 
    String pkg = mAdapter.getItem(position).toString(); 
    boolean isProtected = ApplicationUtils.isPackageProtected(this, pkg) != null; 
    PreferenceUtils.setPreference(mContext, null, pkg, !isProtected, false); 
    Handler adapterHandler = new Handler(); 
    adapterHandler.postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      mAdapter.notifyDataSetChanged(); 
     } 
    }, 500); 
} 

누군가가 내게 왜 이런 일이 발생하는지 알려주고 다른 해결책이 있는지 말해 줄 수 있습니까?

감사합니다.

답변

0

사용중인 샘플 코드의 버그입니다. 나는 그것을 고쳤다. 자세한 내용은 this gist의 마지막 의견을 확인하고 this 수정 사항은

입니다.