Comment supprimer un element d'une HashMap

Fermé
asmalak Messages postés 8 Date d'inscription samedi 14 mars 2015 Statut Membre Dernière intervention 24 avril 2015 - 16 avril 2015 à 13:12
BunoCS Messages postés 15948 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 31 mars 2025 - 16 avril 2015 à 13:54
Bonjour,
je veux supprimer un élément d'une HashMap en cliquant sur un bouton "suprimer"

voici une partie du code , mais le message de dialogue ne marche pas.
HistFile = (HistoryFileManager) getIntent().getParcelableExtra(
				MainActivity.PAR_KEY);
		// Adding menuItems to ListView
		// android.R.layout.activity_list_item;
		final ListAdapter adapter = new SimpleAdapter(this, HistFile.menuItems,
				R.layout.list_application, new String[] {
						HistFile.KEY_NOM_APPLICATION,
						HistFile.KEY_DATE_CREATION },
				new int[] { R.id.textViewNameApplication,
						R.id.textViewDateCreation });

		listView1.setAdapter(adapter);
		



Button btn_DeleteItem = (Button)findViewById(R.id.buttonDeleteItem);
		 
		    
		
		btn_DeleteItem.setOnClickListener(new OnClickListener() {
						@Override
			public void onClick(View v) {
				AlertDialog.Builder builder1 = new AlertDialog.Builder(v
						.getContext());

				DialogInterface.OnClickListener listenerYes1 = new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int position) {
						//Traitement à faire
		

						
						
						 
                        
                    
                    
						Toast.makeText(getApplicationContext(),
								"Suppression réussie", Toast.LENGTH_SHORT)
								.show();
					}

			};

			DialogInterface.OnClickListener listenerNo1 = new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						// User cancelled the dialog
					 dialog.cancel();
				}				};

				builder1.setMessage(R.string.supprimerApplication)
					.setPositiveButton(R.string.yes, listenerYes1)
					.setNegativeButton(R.string.no, listenerNo1);

				AlertDialog d1 = builder1.create();
				d1.setTitle("Supprimer application");
				d1.show();

		}
		});

	}

1 réponse

BunoCS Messages postés 15948 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 31 mars 2025 3 914
16 avril 2015 à 13:54
Hello,

Il y a un problème d'indentation dans ton code qui ne le rend que très peu lisible... Néanmoins, j'y détecte une anomalie: d'après ton screenshot, tu as plusieurs bouton "Supprimer". Or, tu n'attaches qu'une fois ton ClickListener...
0