Jump to content

listView / row


Olivier

Recommended Posts

'lut tout le monde,

Ma question du jour :

- j'ai une list view avec un customadapter

- comment obtenir une view sur une row à partir de l'id ou de la position de la row dans la listview

Ca me parrait bête mais là j'ai pas trouvé...

Edited by Olivier
Link to comment
Share on other sites

Je viens justement de bosser cette partie ce matin ;)

Je te file un bout de code que tu adapteras à ton appli :


@Override
   public boolean onContextItemSelected(MenuItem item) {  // Quand un élément du menu contextuel (clic long sur un item) est selected
       return applyContextMenuChoice(item) || super.onContextItemSelected(item);
   }
   private boolean applyContextMenuChoice(MenuItem item) {

               AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();

               // Pour l'exemple, on va dire que l'adapter de ta ListView contient des élément de type "Test"

               Test t = (Test) getListView().getItemAtPosition(menuInfo.position);

               // A partir de là, tu as récupérer l'élément de ta liste sur lequel tu as fais un clic long afficher ton menu contextuel.
               // Tu peux maintenant appeler ses méthodes, exemple :

               String chaine = t.recupererTitre();


       return true;
   }

source : http://www.anddev.org/tinytutcontextmenu_for_listview-t4019.html

Edited by TeChn4K
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...