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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| public class DrawerAdapter extends BaseAdapter {
//ListItem
private String[] listItem;
//Le contexte dans lequel est présent notre adapter
private Context mContext;
//Un mécanisme pour gérer l'affichage graphique depuis un layout XML
private LayoutInflater mInflater;
public DrawerAdapter(Context context, String[] aListP) {
mContext = context;
listItem = aListP;
mInflater = LayoutInflater.from(mContext);
}
public int getCount() {
return listItem.length;
}
public Object getItem(int position) {
return listItem[position];
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout layoutItem;
//(1) : Réutilisation des layouts
if (convertView == null) {
//Initialisation de notre item à partir du layout XML "personne_layout.xml"
layoutItem = (LinearLayout) mInflater.inflate(R.layout.item_drawer, parent, false);
}
else {
layoutItem = (LinearLayout) convertView;
}
ImageView image = (ImageView) layoutItem.findViewById(R.id.icon_drawer);
TextView text = (TextView) layoutItem.findViewById(R.id.text_drawer);
//INSERTION DES VALEURS
text.setText(listItem[position]);
//COULEUR DU TEXT
text.setTextColor(Color.WHITE);
//POUR LES TITRES
if(position == 0 || position == 5){
layoutItem.setBackgroundColor(ContextCompat.getColor(mContext,R.color.blue1));
text.setTextSize(23);
text.setPadding(10,5,5,5);
}
//POUR LE A PROPOS
else if(position == 2){
layoutItem.setBackgroundColor(ContextCompat.getColor(mContext,R.color.red1));
}
else if(position%2 == 0){
layoutItem.setBackgroundColor(ContextCompat.getColor(mContext,R.color.blue2));
}
else{
layoutItem.setBackgroundColor(ContextCompat.getColor(mContext,R.color.blue3));
}
//METTRE LES ICONS
setIcon(position,image);
//On retourne l'item créé.
return layoutItem;
}
public void setIcon(int position,ImageView image){
if(position == 1){
image.setImageResource(R.mipmap.ico_home);
}
else if(position == 2){
image.setImageResource(R.mipmap.ico_question);
}
else if(position == 3){
image.setImageResource(R.mipmap.ico_a_propos);
}
else if(position == 4){
image.setImageResource(R.mipmap.ico_contact);
}
else if(position == 6){
image.setImageResource(R.mipmap.ico_conso);
}
else if(position == 7){
image.setImageResource(R.mipmap.ico_relations);
}
else if(position == 8){
image.setImageResource(R.mipmap.ico_religions);
}
else if(position == 9){
image.setImageResource(R.mipmap.ico_sante);
}
else if(position == 10){
image.setImageResource(R.mipmap.ico_scolarite);
}
else if(position == 11){
image.setImageResource(R.mipmap.ico_sexualite);
}
else if(position == 12){
image.setImageResource(R.mipmap.ico_violences);
}
else if(position == 13){
image.setImageResource(R.mipmap.ico_divers);
}
}
} |
Partager