사용자 정의 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을 누를 때도 나타나지 않습니다 ...
내가 전화 한 것은 onItemClickListener가 아니라 onChildClickListener()입니다. 뭐가 잘못 됐는지 모르겠다.하지만 나는 adapter.notifyDataSetChanged를 호출 할 수 없었다. 알리미와 알림 만받습니다. – Jovi
어댑터를 어디에서 신고 했습니까? 그것은 클래스 변수입니까? onClick 메서드를 게시하십시오 ... – Rotemmiz
자세한 내용을 추가했습니다 =) – Jovi