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
|
package com.example.ex1
import java.util.ArrayList;
import java.util.HashMap;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.RemoteViews;
import android.widget.SimpleAdapter;
@SuppressLint("NewApi")
public class MainActivity extends AppWidgetProvider {
private static ListView maListViewPerso;
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
for (int i = 0; i < N; i++)
{
int appWidgetId = appWidgetIds[i];
updateAppWidget(context, appWidgetManager, appWidgetId);
}
}
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId)
{
//Récupération de la listview créée dans le fichier main.xml
maListViewPerso = (ListView) findViewById(R.id.listViewPerso);
//Création de la ArrayList qui nous permettra de remplire 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;
//Création d'une HashMap pour insérer les informations du premier item de notre listView
map = new HashMap<String, String>();
//on insère un élément titre que l'on récupérera dans le textView titre créé dans le fichier affichageitem.xml
map.put("titre", "Word");
//on insère un élément description que l'on récupérera dans le textView description créé dans le fichier affichageitem.xml
map.put("description", "Editeur de texte");
//on insère la référence à l'image (convertit en String car normalement c'est un int) que l'on récupérera dans l'imageView créé dans le fichier affichageitem.xml
map.put("img", String.valueOf(R.drawable.word));
//enfin on ajoute cette hashMap dans la arrayList
listItem.add(map);
//On refait la manip plusieurs fois avec des données différentes pour former les items de notre ListView
map = new HashMap<String, String>();
map.put("titre", "Excel");
map.put("description", "Tableur");
map.put("img", String.valueOf(R.drawable.excell));
listItem.add(map);
map = new HashMap<String, String>();
map.put("titre", "Power Point");
map.put("description", "Logiciel de présentation");
map.put("img", String.valueOf(R.drawable.powerpoint));
listItem.add(map);
map = new HashMap<String, String>();
map.put("titre", "Outlook");
map.put("description", "Client de courrier électronique");
map.put("img", String.valueOf(R.drawable.outlook));
listItem.add(map);
//Création d'un SimpleAdapter qui se chargera de mettre les items présent dans notre list (listItem) dans la vue affichageitem
SimpleAdapter mSchedule = new SimpleAdapter (context, listItem, R.layout.affichage_item,
new String[] {"img", "titre", "description"}, new int[] {R.id.img, R.id.titre, R.id.description});
}
} |
Partager