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 :

probléme code listeview


Sujet :

Android

  1. #1
    Membre très actif
    Inscrit en
    Mars 2011
    Messages
    230
    Détails du profil
    Informations forums :
    Inscription : Mars 2011
    Messages : 230
    Par défaut probléme code listeview
    salut j'ai crée une listeview mais le probléme j'ai une erreur dans List view
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), listItem, R.layout.affichageitem,
                   new String[] {"img", "titre", "description"}, new int[] {R.id.img, R.id.titre, R.id.description});


    Uploaded with ImageShack.us
    voila les deux fichier xml
    Code : 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
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <EditText
        android:id="@+id/password"
        android:password="true"
         android:layout_height="wrap_content"
          android:layout_width="fill_parent" 
     
     
          android:inputType="textPassword|number">
           </EditText>
     
        <Button android:layout_height="wrap_content" android:layout_width="fill_parent" 
        android:id="@+id/ok"
        android:hint="Entrez des chiffres" 
       android:digits="0123456789"
       android:maxLines="1"
       android:maxLength="5"
       android:inputType="phone|number"
       android:typeface="monospace"
         android:text="Enter"></Button>
     
        <ListView android:layout_height="wrap_content"
         android:id="@+id/listView1" 
         android:layout_width="fill_parent"></ListView>
     
    </LinearLayout
    Code : 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
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >
     
        <ImageView
    		android:id="@+id/img"
    		android:layout_width="wrap_content"
    		android:layout_height="wrap_content"
    	   	android:layout_gravity="center_vertical"
    	   	android:padding="10px"
    		/>
     
    	<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    	    android:orientation="vertical"
    	    android:layout_width="fill_parent"
    	    android:layout_height="wrap_content"
    	   	android:layout_gravity="center_vertical"
    	   	android:paddingLeft="10px"
    	    android:layout_weight="1"
    	    >
     
    	    <TextView android:id="@+id/titre"
    	         android:layout_width="fill_parent"
    	         android:layout_height="fill_parent"
    	         android:textSize="16px"
    	         android:textStyle="bold"
    	         />
     
    	    <TextView android:id="@+id/description"
    	         android:layout_width="fill_parent"
    	         android:layout_height="fill_parent"
    	         />
     
        </LinearLayout>
     
    </LinearLayout>
    si vous plait une autre question comment je crée une sous liste par exemple si je clique sur 1 ére choix je trouve une autre liste
    merci

  2. #2
    Rédacteur
    Avatar de Viish
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Février 2009
    Messages
    427
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

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

    Informations forums :
    Inscription : Février 2009
    Messages : 427
    Par défaut
    Bonsoir,

    Votre problème est lié au fait que Eclipse ne build pas votre application dynamiquement (si les fichiers xml sont bien nommés).
    Essayez de le lancer et ça devrait marcher (ça forcera le build). Ou vous pouvez configurer Eclipser pour builder le code à chaque sauvegarde.

  3. #3
    Membre très actif
    Inscrit en
    Mars 2011
    Messages
    230
    Détails du profil
    Informations forums :
    Inscription : Mars 2011
    Messages : 230
    Par défaut
    j'ai fermé et toujours le mémé problème alors comment je configure le builder

  4. #4
    Membre chevronné
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    322
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 322
    Par défaut
    Bonjour,
    Je ne vois pas la listView avec l'id "listviewperso", Ca ne serait pas plutôt listView1 ?

    Ensuite regarde dans ta classe qu'eclipse n'a pas importé par erreur R.android. Si c'est le cas supprime et normalement ça devrait marcher.

  5. #5
    Membre très actif
    Inscrit en
    Mars 2011
    Messages
    230
    Détails du profil
    Informations forums :
    Inscription : Mars 2011
    Messages : 230
    Par défaut probléme code
    j'ai voulu faire une application quand l'utlisateur tape son mot de passe il s'affiche une liste
    alors j'ai crée 2 classe
    1ére classe pour mot de passe et verifcation de fichier
    2 éme classe pour liste
    1ére class main
    Code : 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
    public class main extends Activity implements OnClickListener, OnKeyListener {
        /** Called when the activity is first created. */
       /*Display display=null;*/
        EditText password;
        Button ok;
     
     
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            password= (EditText)findViewById(R.id.password);
            ok= (Button)findViewById(R.id.ok);
     
            ok.setOnClickListener(this);
            password.setOnClickListener(this);
     
            final String TESTSTRING = new String("1234"); 
     
    		// ##### Write a file to the disk #####
    		/* We have to use the openFileOutput()-method 
    		 * the ActivityContext provides, to
    		 * protect your file from others and 
    		 * This is done for security-reasons. 
    		 * We chose MODE_WORLD_READABLE, because
    		 *  we have nothing to hide in our file */		
    		FileOutputStream fOut;
    		try {
    			fOut = openFileOutput("fichier.txt", 
    								MODE_WORLD_READABLE);
     
    		OutputStreamWriter osw = new OutputStreamWriter(fOut);	
     
    		// Write the string to the file
    		osw.write(TESTSTRING);
    		/* ensure that everything is 
    		 * really written out and close */
    		osw.flush();
    		osw.close();
    		} catch (FileNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		// ##### Read the file back in #####
    		catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
     
     
     
        }
       /*final EditText nameField = (EditText) findViewById(R.id.editText);  */
     
     
    	public void sendFeedback(View button) {  
     
     
    	     String name1 =password.getText().toString();
    	    /* System.out.print("name1="+name1);*/
    	      //nameField.getText().toString();  
    	     try {
    	     FileInputStream fIn = openFileInput("fichier.txt");
    			InputStreamReader isr = new InputStreamReader(fIn);
    			/* Prepare a char-Array that will 
    			 * hold the chars we read back in. */
    			char[] inputBuffer = new char[name1.length()];
    			// Fill the Buffer with data from the file
     
    				isr.read(inputBuffer);
     
     
    				String readString = new String(inputBuffer);
     
     
    			if (readString.equals(name1)){
    				 Toast.makeText(this,"Mot de passe correct",Toast.LENGTH_SHORT).show();	   
    			     /*Tutoriel5_Android aa=new Tutoriel5_Android();
    			     aa.showDialog(BIND_AUTO_CREATE);*/
    			} else{
    			     Toast.makeText(this,"Mot de passe Incorrect",Toast.LENGTH_SHORT).show();
     
    		       // Do click handling here  
    		    }
    			} catch (IOException e) {
    			     Toast.makeText(this,"Une erreur est survenue",Toast.LENGTH_SHORT).show();
     
    				e.printStackTrace();
    			}
    }
     
     
    	@Override
    	public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
    		// TODO Auto-generated method stub
    		return false;
    	}
     
     
    	@Override
     
    		public void onClick(View v) {
                sendFeedback(ok);
        }
    }
    2 éme classe pour la liste
    Code : 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
     public class Tutoriel5_Android extends Activity {
     
    	private ListView maListViewPerso;
     
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
     
            //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", "compte");
            //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", "opération de compte");
            //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
     
            //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", "opération financière");
            map.put("description", "trasfert de solde");
     
            listItem.add(map);
     
            map = new HashMap<String, String>();
            map.put("titre", "Suvie");
            map.put("description", "partie wap");
     
            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 (this.getBaseContext(), listItem, R.layout.affichageitem,
                   new String[] {"img", "titre", "description"}, new int[] {R.id.img, R.id.titre, R.id.description});
     
            //On attribut à notre listView l'adapter que l'on vient de créer
            maListViewPerso.setAdapter(mSchedule);
     
            //Enfin on met un écouteur d'évènement sur notre listView
            maListViewPerso.setOnItemClickListener(new OnItemClickListener() {
    			@Override
            	@SuppressWarnings("unchecked")
             	public void onItemClick(AdapterView<?> a, View v, int position, long id) {
    				//on récupère la HashMap contenant les infos de notre item (titre, description, img)
            		HashMap<String, String> map = (HashMap<String, String>) maListViewPerso.getItemAtPosition(position);
            		//on créer une boite de dialogue
            		AlertDialog.Builder adb = new AlertDialog.Builder(Tutoriel5_Android.this);
            		//on attribut un titre à notre boite de dialogue
            		adb.setTitle("Sélection Item");
            		//on insère un message à notre boite de dialogue, et ici on affiche le titre de l'item cliqué
            		adb.setMessage("Votre choix : "+map.get("titre"));
            		//on indique que l'on veut le bouton ok à notre boite de dialogue
            		adb.setPositiveButton("Ok", null);
            		//on affiche la boite de dialogue
            		adb.show();
            	}
             });
     
        }
    }
    et aussi j'ai créé de fichier xml
    affichageitem
    Code : 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
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >
     
        <ImageView
    		android:id="@+id/img"
    		android:layout_width="wrap_content"
    		android:layout_height="wrap_content"
    	   	android:layout_gravity="center_vertical"
    	   	android:padding="10px"
    		/>
     
    	<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    	    android:orientation="vertical"
    	    android:layout_width="fill_parent"
    	    android:layout_height="wrap_content"
    	   	android:layout_gravity="center_vertical"
    	   	android:paddingLeft="10px"
    	    android:layout_weight="1"
    	    >
     
    	    <TextView android:id="@+id/titre"
    	         android:layout_width="fill_parent"
    	         android:layout_height="fill_parent"
    	         android:textSize="16px"
    	         android:textStyle="bold"
    	         />
     
    	    <TextView android:id="@+id/description"
    	         android:layout_width="fill_parent"
    	         android:layout_height="fill_parent"
    	         />
     
        </LinearLayout>
     
    </LinearLayout>
    2 éme fichier main
    Code : 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
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <EditText
        android:id="@+id/password"
        android:password="true"
         android:layout_height="wrap_content"
          android:layout_width="fill_parent" 
     
     
          android:inputType="textPassword|number">
           </EditText>
     
        <Button android:layout_height="wrap_content" android:layout_width="fill_parent" 
        android:id="@+id/ok"
        android:hint="Entrez des chiffres" 
       android:digits="0123456789"
       android:maxLines="1"
       android:maxLength="5"
       android:inputType="phone|number"
       android:typeface="monospace"
         android:text="Enter"></Button>
     
     
        <ListView android:layout_height="wrap_content"
         android:id="@+id/listView" 
     
     
         android:layout_width="fill_parent"></ListView>
            <ListView
            android:id="@+id/listView1 "
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
          />
     
    </LinearLayout>
    mais le probléme je tombe dans l'erreur dont 2 éme classe dans l'ID
    http://img560.imageshack.us/i/erreur.png/

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème code de la fonction Rechercher et Remplacer
    Par LaPanic dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 25/06/2007, 17h10
  2. Problème code VBA :)
    Par Freygolow dans le forum Access
    Réponses: 4
    Dernier message: 17/05/2007, 15h43
  3. Probléme code C
    Par conceicao dans le forum C
    Réponses: 12
    Dernier message: 23/01/2007, 13h44
  4. Réponses: 6
    Dernier message: 23/12/2006, 12h46
  5. [Problème code] Afficher/Masquer div
    Par glloq8 dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 24/03/2006, 14h18

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