Bonjour,
je suis actuellement sur le développement d'une application android, ou je dois avoir la possibilité de pouvoir envoyer sur un site ftp des fichiers xml. Pour cela, sur ma tablette j'ai un répertoire ou il y a plusieurs sous-répertoires dedans et chaque sous-répertoire possède au minimum 1 fichier xml. J'ai donc créer une expandable list ou apparaît mes différents sous-répertoire et lorsque je clic dessus la liste de ces fichiers apparaît en dessous avec des checkbox permettant de choisir les fichiers à sélectionner pour les envoyer sur le site ftp. Seulement, je n'arrive pas a savoir comment récupérer les éléments sélectionnés.
Voici mon code :
Cette classe me permet de récupérer tous les nom de répertoire contenu dans mon répertoire data et également de récupérer tous les noms des fichiers xml associé afin de pouvoir les afficher par la suite :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116 public class ListAdapter extends BaseExpandableListAdapter { public ArrayList<String> groupItem; public ArrayList<String> tempChild; public ArrayList<Object> objectSelection; public ArrayList<Object> ChildItem = new ArrayList<Object>(); public LayoutInflater inFlater; public Activity activity; public CheckBox cb; public CheckedTextView ctv; public ListAdapter(ArrayList<String> grList, ArrayList<Object> childItem) { groupItem = grList; this.ChildItem = childItem; } public void setInflater(LayoutInflater inf, Activity act) { this.inFlater = inf; activity = act; } public int getGroupCount() { return groupItem.size(); } @SuppressWarnings("unchecked") public int getChildrenCount(int groupPosition) { return ((ArrayList<String>) ChildItem.get(groupPosition)).size(); } public Object getGroup(int groupPosition) { return null; } public Object getChild(int groupPosition, int childPosition) { return null; } public long getChildId(int groupPosition, int childPosition) { return 0; } public boolean hasStableIds() { return false; } public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { if (convertView == null) { convertView = inFlater.inflate(R.layout.group_row, null); } ((CheckedTextView) convertView).setText(groupItem.get(groupPosition)); ((CheckedTextView) convertView).setChecked(isExpanded); return convertView; } @SuppressWarnings("unchecked") public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { tempChild = (ArrayList<String>) ChildItem.get(groupPosition); TextView text = null; if (convertView == null) { convertView = inFlater.inflate(R.layout.child_row, null); } else { cb = (CheckBox) convertView.findViewById(R.id.check1); cb.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { } }); } text = (TextView) convertView.findViewById(R.id.textView1); text.setText(tempChild.get(childPosition)); convertView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { } }); return convertView; } public boolean isChildSelectable(int groupPosition, int childPosition) { return false; } public void onGroupCollapsed(int groupPosition) { super.onGroupCollapsed(groupPosition); } public void onGroupExpanded(int groupPosition) { super.onGroupExpanded(groupPosition); } public long getGroupId(int groupPosition) { return 0; } }
Merci de votre aide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 public class ListFileMeasureActivity extends ExpandableListActivity implements OnChildClickListener { String DATA_PATH = Environment.getExternalStorageDirectory() + "/Data"; DiskFileExplorer c; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ExpandableListView elv = getExpandableListView(); elv.setDividerHeight(2); elv.setGroupIndicator(null); elv.setClickable(true); setGroupData(); setChildGroupData(); ListAdapter na = new ListAdapter(groupItem, childItem); na.setInflater( (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE), this); getExpandableListView().setAdapter(na); elv.setOnChildClickListener(this); } public void setGroupData() { c = new DiskFileExplorer(DATA_PATH, true); DiskFileExplorer.listDirectory(DATA_PATH); /** Parcours la liste des repertoires **/ for (String list : DiskFileExplorer.listDir) { groupItem.add(list); } } ArrayList<String> groupItem = new ArrayList<String>(); static ArrayList<Object> childItem = new ArrayList<Object>(); public void setChildGroupData() { DiskFileExplorer.listDirectory(DATA_PATH); /** Parcours la liste des repertoires **/ for (String list : DiskFileExplorer.listDir) { ArrayList<String> child = new ArrayList<String>(); File fileDir = new File(DATA_PATH + "/" + list); File[] files = fileDir.listFiles(); /** Parcours la liste des fichiers du repertoire **/ for (File listfile : files) { if (listfile.getName().endsWith(".xml")) { child.add(listfile.getName()); } } childItem.add(child); } } /** * Méthode onChildClick() * * @param parent * : expandableListView ou le clic a été effectue * @param v * : la vue ou çà a été effectué * @param groupPosition * : le group dans lequel l'élément a été cliqué * @param childPosition * : la position de l'élément dans le groupe * @param id * : * @return boolean si un élément a été cliqué */ public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { CheckBox cb = (CheckBox) v.findViewById(R.id.check1); if (cb != null) cb.toggle(); Toast.makeText(ListFileMeasureActivity.this, "Clicked On Child", Toast.LENGTH_SHORT).show(); return false; } }
Partager