IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Choisir un item d'une listeview


Sujet :

Android

  1. #1
    Membre du Club
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2014
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2014
    Messages : 6
    Par défaut Choisir un item d'une listeview
    Bonjour,

    Voici ma listeview :

    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
     
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         >
     
        <ListView
            android:id="@+id/listemployes"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:dividerHeight="0.1dp"
            android:divider="#0000CC">
        </ListView>
     
    </FrameLayout>

    Voici ma relative layout :

    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
     
    <?xml version="1.0" encoding="utf-8"?>
     
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="2dp"
     
     
        >
     
     
        <TextView
            android:id="@+id/textViewNom"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@+id/profile_pic"
            android:paddingBottom="10dp"
            android:textSize="20sp"
            android:textColor="@color/blue"
    	    android:textStyle="bold"
    	    android:width="140dp"
     
    	    />
     
         <TextView
            android:id="@+id/textViewPrenom"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textViewNom"
            android:layout_below="@+id/textViewNom"
            android:textSize="16sp" />
     
     
          <TextView
            android:id="@+id/textViewTelephone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/textViewPrenom"
            android:layout_alignBottom="@+id/textViewPrenom"
            android:layout_alignParentRight="true"
            android:textSize="16sp"
     
    	     />
     
     
     
              <Button
            android:id="@+id/btn_details"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:text="Plus de détails"
            android:layout_alignLeft="@+id/textViewTelephone"
            android:layout_below="@+id/textViewTelephone"
            android:layout_alignParentLeft="true"
            android:layout_marginTop="15dip"
            android:layout_marginLeft="110dip"
            android:onClick="transferer"/>
     
     
     
    </RelativeLayout>


    Activités(tout en sachant que je récupère les données depuis une base de données) :

    Code Java : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
     
     
     
    protected void onCreate(Bundle savedInstanceState) {
     
    		super.onCreate(savedInstanceState);
     
    		setContentView(R.layout.my_activity);
     
     
     
    		lv =  (ListView) findViewById(R.id.listemployes);
     
     
     
    		 TaskWs task = new TaskWs(); 
     
     
     
    		 task.execute();
     
     
     
    	}	
     
    public void transferer(View v) {
     
              TextView tv_telephone = (TextView)findViewById(R.id.textViewTelephone);
             final String telephone = tv_telephone.getText().toString();
     
     
             TextView TVnom = (TextView)findViewById(R.id.textViewNom);
             String nom = TVnom.getText().toString();
     
             TextView TVprenom = (TextView) findViewById(R.id.textViewPrenom);
             String prenom = TVprenom.getText().toString();
     
     
     
     
    	      ad = new AlertDialog.Builder(MyActivity.this)
    	        .setTitle("Employé")
    	        .setMessage("Nom : "+nom)
                    .setMessage("Prénom : "+prenom)
    	        .setSingleChoiceItems(monadaptateur, -1, new DialogInterface.OnClickListener() {
     
    				@Override
    				public void onClick(DialogInterface dialog, int which) {
    					Toast.makeText(getApplicationContext(), "appeler "+telephone, Toast.LENGTH_LONG).show();
                        dialog.cancel();
     
    				}
    			})
    	        .setPositiveButton("Appeler",
    	                new DialogInterface.OnClickListener() {
     
    	                    public void onClick(DialogInterface dialog, int id) {
     
     
                                     Intent callIntent = new Intent(Intent.ACTION_CALL);
    				 callIntent.setData(Uri.parse(telephone.trim()));
    			         startActivity(callIntent );
     
    	                        dialog.cancel();
    	                    }
    	                })
     
     
    	        .setNegativeButton("Ajouter contact", new DialogInterface.OnClickListener() {
     
    	            public void onClick(DialogInterface dialog, int id) {
     
     
         ArrayList < ContentProviderOperation > ops = new ArrayList < ContentProviderOperation > ();
     
    				 ops.add(ContentProviderOperation.newInsert(
    				 ContactsContract.RawContacts.CONTENT_URI)
    				     .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
    				     .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
    				     .build());
     
     
    				 if (nom != null) {
    				     ops.add(ContentProviderOperation.newInsert(
    				     ContactsContract.Data.CONTENT_URI)
    				         .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
    				         .withValue(ContactsContract.Data.MIMETYPE,
    				     ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
    				         .withValue(
    				     ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
    				     nom).build());
    				 }
     
     
    				 if (telephone != null) {
    				     ops.add(ContentProviderOperation.
    				     newInsert(ContactsContract.Data.CONTENT_URI)
    				         .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
    				         .withValue(ContactsContract.Data.MIMETYPE,
    				     ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
    				         .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, telephone)
    				         .withValue(ContactsContract.CommonDataKinds.Phone.TYPE,
    				     ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE)
    				         .build());
    				 }
     
    	                dialog.cancel();
    	            }
    	        }).show();
     
    	}
     
     
     
     
     
     
     
     
     
     
     
     
     
    }








    Ce qui marche :

    * La liste s'affiche normalement avec ses items(et donc aucun problème avec la base).
    * Ajouter contact marche normalement.


    Ce qui ne marche pas :

    1) Appeler : ne marche pas ! avec un message d'erreur :

    "android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=003312345678 }"

    2) quand je clique sur un item, c'est les données d'un autre item qui s'affiche!!!!

    3) Avec une "alertDialog" je peux pas afficher plusieurs données????

    .setMessage("Nom : "+nom)
    .setMessage("Prénom : "+prenom)
    .setMessage("Téléphone : "telephone)

    ça ne marche pas!!



    Objectifs :

    Donc je dois avoir une liste de mes employés(c'est bon) :

    Nom
    Prenom
    Telephone

    [Plus de détails]

    Ou même sans bouton ! Le plus important quand je clique sur "item" une "AlertDialog" s'affiche et me propose tous les détails :

    Nom
    Prenom
    Telephone
    Mail
    Adresse

    avec 2 boutons : [Appeler] / [Ajouter contact]



    Remarque :

    J'ai essayé une autre méthode :

    Code Java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
     
    lv.setOnItemClickListener(new OnItemClickListener() {
     
     
    	public void onItemClick(AdapterView<?> parent, View viewItem, int position, long arg3) throws NullPointerException {
     
    }



    mais ça n'a pas marché!!!! (Quand je clique sur un item rien ne se passe)


    Je vous remercie d'avance.

  2. #2
    Membre du Club
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2014
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2014
    Messages : 6
    Par défaut

    1) Appeler : ne marche pas ! avec un message d'erreur :

    "android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=003312345678 }"

    2) quand je clique sur un item, c'est les données d'un autre item qui s'affiche!!!!

    3) Avec une "alertDialog" je peux pas afficher plusieurs données????

    .setMessage("Nom : "+nom)
    .setMessage("Prénom : "+prenom)
    .setMessage("Téléphone : "telephone)

    ça ne marche pas!!

    Pour la 1ère question(appel) j'ai trouvé la réponse :

    j'ai remplacé ce code :

    Code Java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
     
    Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse(telephone.trim()));
    startActivity(callIntent );


    par celui ci :

    Code Java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
     
     
     
     
        	try {
     
    	                    	String uri = "tel:"+tv_telephone.getText().toString();
     
    	                    	Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(uri));
     
     
     
    	                        startActivity(callIntent);
     
    	                    } catch(Exception e) {
     
    	                        Toast.makeText(getApplicationContext(),"Echec de l'appel ... "+e.getMessage(),
     
    	                            Toast.LENGTH_LONG).show();
     
    	                        e.printStackTrace();
     
    	                    }

    ça marche parfaitement.

  3. #3
    Membre émérite
    Avatar de LeBzul
    Homme Profil pro
    Inscrit en
    Décembre 2008
    Messages
    381
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations forums :
    Inscription : Décembre 2008
    Messages : 381
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    .setMessage("Nom : "+nom)
    .setMessage("Prénom : "+prenom)
    .setMessage("Téléphone : "telephone)
    Correspond à :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    monMessage = "Nom :"+nom;
    monMessage = "Prénom : "+prenom;
    monMessage = "Téléphone : "+telephone;
    Le message qui apparaît est donc le dernier : "Téléphone : "+telephone;
    Si tu veux avoir un message avec tout dedans il faut lui donner qu'une fois la valeur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    monMessage = "Nom :"+nom+" "+"Prénom : "+prenom+" "+ "Téléphone : "+telephone;
    L'addition de string n'est pas terrible, il est préférable d'utiliser un StringBuffer :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    new StringBuffer().append("Nom").append(nom).append(.....).toString();

  4. #4
    Membre du Club
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2014
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2014
    Messages : 6
    Par défaut
    @LeBzul

    merci pour votre aide ! ça marche !


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
     
    StringBuffer monMessage = new StringBuffer().append("Nom : ").append(nom)
            		                                     .append((System.getProperty("line.separator")))
            		                                     .append("Téléphone : ")
            		                                     .append(telephone);

    Récapitulatif :


    3 Questions :


    (1) Appeler : ne marche pas ! avec un message d'erreur :

    "android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=003312345678 }"

    (2) quand je clique sur un item, c'est les données d'un autre item qui s'affiche!!!!

    (3) Avec une "alertDialog" je peux pas afficher plusieurs données????

    .setMessage("Nom : "+nom)
    .setMessage("Prénom : "+prenom)
    .setMessage("Téléphone : "telephone)

    ça ne marche pas!!
    (1) et (3) résolues !

    Il reste le (2) ????

Discussions similaires

  1. [Débutant] Rechercher les items dans une listeview
    Par Martipit dans le forum VB.NET
    Réponses: 14
    Dernier message: 01/10/2012, 22h26
  2. Réponses: 6
    Dernier message: 16/02/2010, 21h34
  3. Réponses: 4
    Dernier message: 13/03/2009, 15h44
  4. Réponses: 1
    Dernier message: 09/12/2007, 18h07
  5. Réponses: 2
    Dernier message: 17/08/2003, 20h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo