2014-09-23 2 views
0

xml 구문 분석에서 확장 가능한 listview에서 데이터를 새로 고친 후 notifydatasetchanged를 호출했지만 응용 프로그램이 손상되고 있습니다. 내 어댑터 클래스가 BaseExpandableListAdapter를 확장하고 있습니다. 나는 다음과 같은 코드를 사용했다 : 방법 "projected_values"에서.notifydatasetchanged가 android의 확장 가능한 목록보기에서 작동하지 않습니다.

class PushNotification extends AsyncTask<String, Void, Void> { 


    @Override 
    protected Void doInBackground(String... arg0) { 
     makeGetRequest(); 
     return null; 
    } 
    @Override 
    protected void onPostExecute(Void result) { 
     // TODO Auto-generated method stub 
     super.onPostExecute(result); 
     listAdapter = new ExpandableListAdapter(ct, values, scores); 
     for(int i=0;i<values.size();i++){ 

     } 
     expListView.setAdapter(listAdapter); 
     listAdapter.notifyDataSetChanged(); 

     expListView.setOnGroupClickListener(new OnGroupClickListener() { 

      @Override 
      public boolean onGroupClick(ExpandableListView parent, View v, 
        int groupPosition, long id) { 
        values.clear(); 
        projected_values(groupPosition); 
       listAdapter.notifyDataSetChanged(); 
       return false; 
      } 
     }); 

그룹 클릭 리스너를 들어, 내가 포기하고 값을. 오류 다음 로그 캣 쇼

09-23 02:45:43.469: E/AndroidRuntime(3563): FATAL EXCEPTION: main 
09-23 02:45:43.469: E/AndroidRuntime(3563): Process: com.example.xmlparsing, PID: 3563 
09-23 02:45:43.469: E/AndroidRuntime(3563): java.lang.IllegalStateException: The content of the 
    adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. Make sure your adapter calls notifyDataSetChanged() when its content changes. [in ListView(2131296256, class android.widget.ExpandableListView) with Adapter(class android.widget.ExpandableListConnector)] 
09-23 02:45:43.469: E/AndroidRuntime(3563):  at android.widget.ListView.layoutChildren(ListView.java:1555) 
09-23 02:45:43.469: E/AndroidRuntime(3563):  at android.widget.AbsListView.onTouchUp(AbsListView.java:3617) 
09-23 02:45:43.469: E/AndroidRuntime(3563):  at android.widget.AbsListView.onTouchEvent(AbsListView.java:3429) 
09-23 02:45:43.469: E/AndroidRuntime(3563):  at android.view.View.dispatchTouchEvent(View.java:7690) 
09-23 02:45:43.469: E/AndroidRuntime(3563):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2210) 
09-23 02:45:43.469: E/AndroidRuntime(3563):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1945) 

답변

2

먼저 비동기에서 클릭 수신기를 만들지 마십시오.

오류는 다음과 같습니다 : -

The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. Make sure your adapter calls notifyDataSetChanged() when its content changes. 

이 게시물에

실행 "어댑터의 내용이 백그라운드 스레드에서 수정,하지만 UI 스레드에서 있지 않은지 확인" : -

어댑터 클래스의 새 인스턴스를 만들고이를 listview에 설정하고 동일한 알림을 통보합니다 시각. 이 시점에서 수정 된 데이터가 없으므로 여기서 알림을 호출 할 필요가 없습니다.

+0

나는 내 코드를 수정했다. .. Runonuithread에서 notifydatasetchanged를 작성하고 oncreate ..에서 onclicklisteners를 작성했지만 동일한 오류가 발생했다. – Chowdary102

0

onPostExecute 방법을 쓰기보다는 클래스의 주요 활동 파일의 listAdapter.notifyDataSetChanged(); 쓰기 나 좀 도와주십시오.

관련 문제