2012-01-22 3 views
4

사용자 정의 ExpandableListView에 대해 notifyDataSetChanged를 호출하려고합니다. 내 자식 목록의 경우, 선택한 폴더 (그룹 목록)의 파일을 보여줍니다. 아이를 클릭하면 파일을 삭제할지 여부를 묻는 메시지가 표시됩니다. 그런 다음 삭제 후 ExpandableList가 "새로 고침"됩니다. 하지만 어떻게 든 notifyDataSetChanged 메서드를 호출 할 수 없습니다.커스텀 ExpandableListView에 대해 notifyDataSetChanged를 호출하는 방법은 무엇입니까?

내 사용자 지정 어댑터 :

public class customListAdapter extends BaseExpandableListAdapter { 
    // Sample data set. children[i] contains the children (String[]) for groups[i]. 
    private File mapFolder = new File (Environment.getExternalStorageDirectory(),"/MLT/A"); 
    private File recordFolder = new File (Environment.getExternalStorageDirectory(),"/MLT/B"); 
    private File scribbleFolder = new File (Environment.getExternalStorageDirectory(),"/MLT/C"); 
    private String[] groups = { "A", "B", "C" }; 
    private String[][] children = { mapFolder.list(), recordFolder.list(), scribbleFolder.list() }; 

    public Object getChild(int groupPosition, int childPosition) { 
     return children[groupPosition][childPosition]; 
    } 

    public long getChildId(int groupPosition, int childPosition) { 
     return childPosition; 
    } 

    public int getChildrenCount(int groupPosition) { 
     return children[groupPosition].length; 
    } 

    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, 
           View convertView, ViewGroup parent) { 

     TextView textView = new TextView(MLT_File.this); 
     textView.setBackgroundColor(Color.BLACK); 
     textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); 
     textView.setPadding(100, 5, 0, 5); 
     textView.setTextColor(Color.WHITE); 
     textView.setTextSize(23); 
     textView.setId(1000); 

     textView.setText(getChild(groupPosition, childPosition).toString()); 
     return textView; 
    }//getChildView 

    public Object getGroup(int groupPosition) { 
     return groups[groupPosition]; 
    } 

    public int getGroupCount() { 
     return groups.length; 
    } 

    public long getGroupId(int groupPosition) { 
     return groupPosition; 
    } 

    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, 
      ViewGroup parent) { 
     TextView textView = new TextView(MLT_File.this); 
     textView.setBackgroundColor(Color.WHITE); 
     textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); 
     textView.setPadding(100, 0, 0, 0); 
     textView.setTextColor(Color.BLACK); 
     textView.setTextSize(25); 
     textView.setText(getGroup(groupPosition).toString()); 

     return textView; 
    } 

    public boolean isChildSelectable(int groupPosition, int childPosition) { 
     return true; 
    } 

    public boolean hasStableIds() { 
     return true; 
    } 

    public void notifyDataSetChanged() { 
     this.notifyDataSetChanged(); 
    } 

}//customListAdapter 

내에서 onCreate : 내 사용자의

// Set up our adapter 
    listAdapter = new customListAdapter(); 

    expLV = (ExpandableListView) findViewById(R.id.mlt_expList); 
    expLV.setAdapter(listAdapter); 
    //registerForContextMenu(expLV); 

    expLV.setOnChildClickListener(new OnChildClickListener() 
    { 
     @Override 
     public boolean onChildClick(ExpandableListView parent, View v, 
       int groupPosition, int childPosition, long id) 
     { 
      // TODO Auto-generated method stub 
      String parentName = ""; 
      if (groupPosition == 0) 
      { 
       parentName = "A"; 
      } 

      else if (groupPosition == 1) 
      { 
       parentName = "B"; 
      } 

      else if (groupPosition == 2) 
      { 
       parentName = "C"; 
      } 

      TextView childView = (TextView) v; 
      String childName = childView.getText().toString(); 

      File file = new File(Environment.getExternalStorageDirectory(),"/Folder/"+childName); 
      file.delete(); 

      return false; 
     } 
    });//OnChildClickListener 

notifyDataSetChanged()가 나는 ExpandableList가없는 깨닫고 난,하려고 노력하는 것이다. 하지만 여전히 내가 만든 방법은 expLV.n을 누를 때도 나타나지 않습니다 ...

답변

-1

글쎄 ... 아무도 정말 어떻게하는지 말해주지 않았기 때문에, 나는 바보 같지만 유용 할 수있는 방법을 생각했습니다.

내가 한 일은 오히려 onCreate에서 생성했기 때문에 onResume()에서 생성했습니다. 내가 그것을 바꿀 때, 그것은 다시 만들어 질 것이다. 그 이유는 내가 TabMenu를 사용하고 있기 때문에 그 사이에 전환 할 때 클래스가 다시 만들어지지 않기 때문에 목록이 같은 상태에있게됩니다.

onResume을 사용하여 새로 고침을 원할 때 내 작업을 단순화하므로 onResume()을 호출하면됩니다.

희망이 도움 다른 사람. =)

5

사실, notifyDataSetChanged() function on BaseExpandableListAdapter이 있습니다.

당신과 함께 아무것도 달성하지 않습니다 :

public void notifyDataSetChanged() { 
    this.notifyDataSetChanged(); 
} 

그것을 제거하십시오.

데이터 세트를 변경 한 후 의 onClick(View v)에서 으로 전화하십시오.

+0

내가 전화 한 것은 onItemClickListener가 아니라 onChildClickListener()입니다. 뭐가 잘못 됐는지 모르겠다.하지만 나는 adapter.notifyDataSetChanged를 호출 할 수 없었다. 알리미와 알림 만받습니다. – Jovi

+0

어댑터를 어디에서 신고 했습니까? 그것은 클래스 변수입니까? onClick 메서드를 게시하십시오 ... – Rotemmiz

+0

자세한 내용을 추가했습니다 =) – Jovi

관련 문제