Array list d'objets (comment recupérer les données)
Bonjour,
Je débute en programmation Android et développe généralement en procédural.
Voici mon soucis.
Je crée un objet comme ci dessous.
Code:
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
| public class fichePartition {
private String id,titre,detail,urlImage,niveau,type;
fichePartition(String id,String titre,String detail,String urlImage,String niveau,String type){
this.id=id;
this.titre=titre;
this.detail=detail;
this.urlImage=urlImage;
this.niveau=niveau;
}
public String getId(){
return id;
}
public String getTitre(){
return titre;
}
public String getDetail(){
return detail;
}
public String getUrlImage(){
return urlImage;
}
public String getNiveau(){
return niveau;
}
public String getType(){
return type;
}
} |
Ensuite dans une boucle (après récupération d'inof par http) dans une boucle je le stocke des instance de mon objet dans une Arraylist
Je crée en premier dans ma class MainActivity mon Array list
Code:
1 2
|
List <Object>zrPartition = new ArrayList<Object>(); |
Et puis j'instancie mon objet dans une boucle (dans un thread)
Code:
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
|
urlTxt="http://www.easy-musique.com/EASY_MUSIQUE_WEB/FR/ENV_LISTE_PARTITION.awp";
chargePage maPage = new chargePage();
ListePartition=maPage.charge(urlTxt);
extraitTexte monTxt = new extraitTexte();
tabPartition=monTxt.extrait(ListePartition,"/");
final ProgressDialog monDialogue = new ProgressDialog(this);
monDialogue.setTitle("Chargement des partitions...");
monDialogue.setMessage("Avancement");
monDialogue.setMax(nbrPartitionParPage);
monDialogue.setProgressStyle(monDialogue.STYLE_HORIZONTAL);
monDialogue.show();
new Thread(new Runnable(){
public void run(){
numDepart=nbrPages*(pageEnCours-1);
numFin=numDepart+(nbrPartitionParPage-1);
for (int cont=numDepart;cont<=numFin;cont++){
idPartition=tabPartition.get(cont).toString();
urlTxt="http://www.easy-musique.com/EASY_MUSIQUE_WEB/FR/ENV_FICHE_PARTITION.awp?ID_PARTITION=";
chargePage mapage= new chargePage();
detaillePartition=mapage.charge(urlTxt+idPartition);
extraitTexte monTxt = new extraitTexte();
tabDetaillePartition=monTxt.extrait(detaillePartition,"|");
titre=tabDetaillePartition.get(0).toString();
detail=tabDetaillePartition.get(1).toString();
urlImage=tabDetaillePartition.get(2).toString();
niveau=tabDetaillePartition.get(3).toString();
type=tabDetaillePartition.get(3).toString();
//fichePartition maPartition = new fichePartition(idPartition, titre, detail, urlImage, niveau, type);
zrPartition.add(new fichePartition(idPartition, titre, detail, urlImage, niveau, type));
monDialogue.setProgress(cont);
}
monDialogue.dismiss();
try {
Log.i("INFO","OK");
afficheZrPartition();
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.i("INFO","BAD");
}
}
}).start();
} |
Et voici mon soucis comment récupérer les méthodes de mon objet
Voici le code ou je bloque
Code:
1 2 3 4 5
|
private void afficheZrPartition() throws NoSuchFieldException {
Object maPartition= zrPartition.get(1);
} |