Jump to content

[Résolu] Utilisation d'un layout personnalisé dans un AlerDialog


TsCyrille

Recommended Posts

Bonjour

J'ai défini un layout contenant une ListView. Je veux afficher ce layout dans une AlertDialog. Pour cela je fais ceci :

public void onClick(View v) {
AlertDialog.Builder alertdialog = new AlertDialog.Builder(this);
alertdialog.setView(LayoutInflater.from(this).inflate(R.layout.mon_layout, null));
alertdialog.show();

Ma question est la suivante : comment affecter l'adapter et l'évènement setOnItemLongClickListener a la ListView (avec en plus appel de l'alertdialog dans l'évènement pour fermer cette dernière) ?

Merci d'avance

Link to comment
Share on other sites

Tu peux faire comme sur un Activity lorsque tu inflate ton XML :

View alertView = LayoutInflater.from(this).inflate(R.layout.mon_layout, null);
ListView alertListView = (ListView) alertView.findViewById(R.id.AlertListView);
AlertViewAdapter adapter = new AlertViewAdapter();
alertListView.setAdapter(adapter, ...);
...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...