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
| public class PizzaActivity extends DashboardActivity {
/** Called when the activity is first created. */
// HashMap arraList qui prend les objets
private ArrayList <HashMap<String, Object>> myIng;
private static final String INGREDIENT = "ingnom";
private static final String PRIX = "ingprix";
private static final String IMAGE = "iconfromraw";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_f2);
ListView listView = (ListView)findViewById(R.id.list);
myIng = new ArrayList<HashMap<String,Object>>();
HashMap<String, Object> hm;
// Créée une nouvelle HashMap et définis ses élements
hm = new HashMap<String, Object>();
hm.put(IMAGE, R.drawable.mozza);
hm.put(INGREDIENT, "Mozzarella");
hm.put(PRIX, "Prix : 0.60");
// Ajoute la HashMap créée à la liste
myIng.add(hm);
hm = new HashMap<String, Object>();
hm.put(IMAGE, R.drawable.emmental);
hm.put(INGREDIENT, "Emmental");
hm.put(PRIX, "Prix : 0.50");
myIng.add(hm);
hm = new HashMap<String, Object>();
hm.put(INGREDIENT, "Chèvre");
hm.put(PRIX, "Prix : 0.75");
hm.put(IMAGE, R.drawable.chevre);
myIng.add(hm);
hm = new HashMap<String, Object>();
hm.put(INGREDIENT, "Roquefort");
hm.put(PRIX, "Prix : 0.75");
hm.put(IMAGE, R.drawable.roquefort);
myIng.add(hm);
// Définis un SimpleAdapter et lie les valeurs aux lignes de la vue view R.layout.listview
SimpleAdapter adapter = new SimpleAdapter(this, myIng, R.layout.listview,
new String[]{IMAGE,INGREDIENT,PRIX}, new int[]{R.id.img,R.id.text1, R.id.text2});
listView.setAdapter(adapter);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
} |
Partager