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
| import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class MainMenu extends Activity {
private ListView maListViewPerso;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu);
//Récupération de la listview créée dans le fichier main.xml
maListViewPerso = (ListView) findViewById(R.id.listFiles);
//Création de la ArrayList qui nous permettra de remplir la listView
ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
//On déclare la HashMap qui contiendra les informations pour un item
HashMap<String, String> map;
map = new HashMap<String, String>();
map.put("titre", "MonEspace");
map.put("description", "Mes dossiers/Fichiers");
map.put("img", String.valueOf(R.drawable.icon_monespace));
listItem.add(map);
map = new HashMap<String, String>();
map.put("titre", "Favoris");
map.put("description", "Mes données préférées");
map.put("img", String.valueOf(R.drawable.icon_fav));
listItem.add(map);
map = new HashMap<String, String>();
map.put("titre", "Historique");
map.size();
map.put("description", "Historique des données");
map.put("img", String.valueOf(R.drawable.histo));
listItem.add(map);
map = new HashMap<String, String>();
map.put("titre", "HorsConnexion");
map.put("description", "Mes données hors connexion");
map.put("img", String.valueOf(R.drawable.ic_offline_notification));
listItem.add(map);
map = new HashMap<String, String>();
map.put("titre", "Aide");
map.put("description", "Obtenir de l'aide");
map.put("img", String.valueOf(R.drawable.icon_aide));
listItem.add(map);
SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), listItem, R.layout.item,
new String[] {"img", "titre", "description"}, new int[] {R.id.img, R.id.titre, R.id.description});
maListViewPerso.setAdapter(mSchedule);
maListViewPerso.setOnItemClickListener(new OnItemClickListener() {
@SuppressWarnings("unchecked")
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
HashMap<String, String> map = (HashMap<String, String>) maListViewPerso.getItemAtPosition(position);
switch(position){
case 0:
startActivity(new Intent(getApplicationContext(),
MonEspace.class).putExtra("From",
"PassCodeOff"));
break;
case 1:
Intent Favoris = new Intent(MainMenu.this,Favoris .class);
startActivity(Favoris);
break;
case 2:
Intent Historique= new Intent(MainMenu.this, Historique.class);
startActivity(Historique);
break;
case 3:
Intent HorsConnexion= new Intent(MainMenu.this, HorsConnexion.class);
startActivity(HorsConnexion);
break;
case 4:
Intent Help= new Intent(MainMenu.this, Help.class);
startActivity(Help);
break;
}}
});}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
} |
Partager