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
| /*appel de méthode ->>>*/ afficherNotes(LoadNote());
////////////////////////////////
public Note[] LoadNote() throws IOException{
File[] ListofFile;
File manager = new File(Environment.getExternalStorageDirectory() + "/Notes/");
if (manager.exists()){
ListofFile=manager.listFiles();
Log.v(TAG,"nombre de fichier: " + ListofFile.length);
if(ListofFile.length!=0){
NotesArrayAdapter.clear();
}
Note[] noteArray = new Note[ListofFile.length];
Log.v(TAG,"Taille noteArray: "+ noteArray.length);
Note note = new Note();
for (int index = 0; index<ListofFile.length;index++){
String filename = ListofFile[index].getName();
FileReader inputReader = new FileReader(ListofFile[index]);
BufferedReader in = new BufferedReader(inputReader);
StringBuffer objBuffer = new StringBuffer();
String strLine;
while ((strLine = in.readLine()) != null) {
objBuffer.append(strLine);
objBuffer.append("\n");
}
String content = objBuffer.toString();
note.setName(getNoteName(filename));
note.setContent(content);
note.setFilename(filename);
noteArray[index]=note;
Log.v(TAG,"Nom : "+ noteArray[index].getName());
Log.v(TAG,"Index : "+ index);
Log.v(TAG,"Test inFor: " + noteArray[index].getName());
/* C'est ici que ça coince noteArray est bien remplit dans le For*/
in.close();
}
/*mais il ne l'ait plus ici*/
Log.v(TAG,"Test : " + noteArray[0].getName());
Log.v(TAG,"Test : " + noteArray[1].getName());
return noteArray;
}
return null;
}
/*affichage ListView*/
public void afficherNotes(Note[] noteArray){
Log.v(TAG,"Jepasselà");
if(noteArray==null){
Log.v(TAG,"A plus...");
}
for(int i = 0; i<noteArray.length;i++){
Log.v(TAG,"i :"+i);
Log.v(TAG,"Notes Affichées :"+ noteArray[i].getName());
NotesArrayAdapter.add(noteArray[i].getName());
}
}
public String getNoteName(String filename){
String name = filename.substring(0, (filename.length()-4));
return name;
} |
Partager