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
| public class menu3_Fragment extends Fragment {
View rootview;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootview = inflater.inflate(R.layout.acidamin, container, false);
ListView listViewAcidAmin = (ListView) rootview.findViewById(R.id.listViewAcidAmin);
ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
map = new HashMap<String, String>();
map.put("Nom", "Alanine");
map.put("Code", "A");
map.put("Abv", "Ala");
map.put("Nature", "Apolaire, aliphatique");
map.put("Codon", "GCU, GCC, GCA, GCG");
map.put("ref","1");
listItem.add(map);
//Je n'ai mis qu'un listItem.add afin de ne pas surcharger la page
SimpleAdapter mSchedule = new SimpleAdapter (rootview.getContext(), listItem, R.layout.affichageitems,
new String[] { "Nom"}, new int[] { R.id.type});
listViewAcidAmin.setAdapter(mSchedule);
listViewAcidAmin.setOnItemClickListener(new OnItemClickListener() {
@Override
@SuppressWarnings("unchecked")
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
ListView listViewAcidAmin = (ListView) rootview.findViewById(R.id.listViewAcidAmin);
TextView nom = (TextView) rootview.findViewById(R.id.Nom);
TextView code = (TextView) rootview.findViewById(R.id.Code);
TextView abv = (TextView) rootview.findViewById(R.id.Abv);
TextView nat = (TextView) rootview.findViewById(R.id.Nature);
TextView codon = (TextView) rootview.findViewById(R.id.Codon);
TextView ref = (TextView) rootview.findViewById(R.id.ref);
HashMap<String, String> map = (HashMap<String, String>) listViewAcidAmin.getItemAtPosition(position);
nom.setText(map.get("Nom"));
code.setText(map.get("Code"));
abv.setText(map.get("Abv"));
nat.setText(map.get("Nature"));
codon.setText(map.get("Codon"));
ref.setText(map.get("ref"));
}
});
return rootview;
}
} |
Partager