Probléme arraylist listview
Bonjour , je développe un projet sous android studio et on peut dire que je ne suis pas vraiment un expert en android mais voila j'aurai besoin d'aide .
Pour l'instant sur mon code j'arrive a avoir une list view de mes ordinateurs provenant de ma bdd , mais il faudrait que j'arrive à rajouter le nom de l'os pour chaque ordinateur provenant d'une autre table mais je bloque ....
voici mon code qui crée le tableau pour la list view :
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| package ddec.applicationddec;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
public class Mat_asso_ord extends Activity {
private ListView lv;
private ProgressDialog progressDialog;
public static ArrayList<ordinateur>detail = new ArrayList<>();
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.list_materiel);
lv = (ListView) findViewById(R.id.listViewMa);
chargerJeuDessaie();
rafraichirListView();
}
private void chargerJeuDessaie()
{
progressDialog = progressDialog.show(this,"Affichage du matériel : ordinateur","Telechargement en cours");
MonAsyncTaskHttp monAsyncTaskHttp = new MonAsyncTaskHttp() {
@Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
Mat_asso_ord.detail.clear();
try {
JSONArray jsonArray = new JSONArray(o.toString());
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
ordinateur ord = ordinateur.factoryOrdi(jsonObject);
Mat_asso_ord.detail.add(ord);
rafraichirListView();
}
} catch (JSONException e) {
e.printStackTrace();
}
progressDialog.dismiss();
}
};
monAsyncTaskHttp.execute("requete=getLesecoleetord&etab="+ search_ville.etabSELECT.getId());
}
public void rafraichirListView() {
ArrayAdapter<ordinateur> ordinateuradapter = new ArrayAdapter<ordinateur>(Mat_asso_ord.this, android.R.layout.simple_list_item_1, detail);
lv.setAdapter(ordinateuradapter);
}
} |
voici mon code de ma class java ordinateur :
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 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
| package ddec.applicationddec;
import android.app.Activity;
import org.json.JSONException;
import org.json.JSONObject;
public class ordinateur extends Activity {
private int id_pc;
private int ref_os;
private String marque_pc;
private int ref_type;
private int ref_etab;
public ordinateur(int id_pc, int ref_os, String marque_pc, int ref_type, int ref_etab) {
this.id_pc = id_pc;
this.ref_os = ref_os;
this.marque_pc = marque_pc;
this.ref_type = ref_type;
this.ref_etab = ref_etab;
}
public int getId_pc() {
return id_pc;
}
public void setId_pc(int id_pc) {
this.id_pc = id_pc;
}
public int getRef_os() {
return ref_os;
}
public void setRef_os(int ref_os) {
this.ref_os = ref_os;
}
public String getMarque_pc() {
return marque_pc;
}
public void setMarque_pc(String marque_pc) {
this.marque_pc = marque_pc;
}
public int getRef_type() {
return ref_type;
}
public void setRef_type(int ref_type) {
this.ref_type = ref_type;
}
public int getRef_etab() {
return ref_etab;
}
public void setRef_etab(int ref_etab) {
this.ref_etab = ref_etab;
}
public String toString() {
String lib = ""+ ref_os +" "+ ref_type +" "+marque_pc+"";
return lib;
}
public static ordinateur factoryOrdi(JSONObject jo)
{
ordinateur ord = null;
try {
int id_pc = jo.getInt("id_pc");
int ref_os = jo.getInt("ref_os");
String marque_pc = jo.getString("marque_pc");
int ref_type = jo.getInt("ref_type");
int ref_etab = jo.getInt("ref_etab");
ord = new ordinateur(id_pc,ref_os,marque_pc,ref_type,ref_etab);
} catch (JSONException e) {
e.printStackTrace();
}
return ord;
}
} |
voila mon problème si quelqu’un voit comment je pourrais faire et m'indiquer comment ce serait sympa =)