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

Composants graphiques Android Discussion :

ListView où rien ne s'affiche


Sujet :

Composants graphiques Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    élève
    Inscrit en
    Mars 2015
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Suisse

    Informations professionnelles :
    Activité : élève
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2015
    Messages : 14
    Par défaut ListView où rien ne s'affiche
    Bonjour,
    Je développe une application sur android pour appeller les services d'urgences. Je voudrais faire que sur la vue principale nous avons une liste de tout les pays et avec un barre (la barre recherche fonctionne).
    J'ai voulu modifier le code et plus rien ne s'affiche dans la liste view.
    Voilà mon code: (j'ai pris le code d'un site donc je ne l'ai pas encore adapté, niveau des noms etc)
    Le code java de mon fragment Home
    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
    package com.test.urgencecall;
     
     
    import android.app.Fragment;
    import android.graphics.drawable.Drawable;
    import android.os.Bundle;
    import android.text.Editable;
    import android.text.TextWatcher;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.EditText;
    import android.widget.ListView;
     
    import java.util.ArrayList;
     
     
    public class HomeFragment extends Fragment {
     
     
     
        String[] listNames = { "Chine", "France", "Suisse", "Angleterre", "Amerique", };
     
     
        ArrayList<Food> listFood;
        ListView lv;
        EditText search;
     
        public HomeFragment(){}
     
     
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
            //construction de la vue
            View rootView = inflater.inflate(R.layout.fragment_home, container, false);
     
            lv = (ListView) rootView.findViewById(R.id.listFood);
            search = (EditText) rootView.findViewById(R.id.search);
            Drawable[] listPictures = {
                    getResources().getDrawable(R.mipmap.ic_china),
                    getResources().getDrawable(R.mipmap.ic_french),
                    getResources().getDrawable(R.mipmap.ic_swiss),
                    getResources().getDrawable(R.mipmap.ic_uk),
                    getResources().getDrawable(R.mipmap.ic_us),
            };
     
            listFood = new ArrayList<Food>();
     
            for (int i = 0; i < listPictures.length; i++) {
                listFood.add(new Food(i + 1, listNames[i], listPictures[i]));
            }
     
            lv.setAdapter(new FoodListAdapter(getActivity().getApplicationContext(), listFood));
            search.addTextChangedListener(new TextWatcher() {
     
                @Override
                public void onTextChanged(CharSequence arg0, int arg1, int arg2,
                                          int arg3) {
                    // TODO Auto-generated method stub
     
                }
     
                @Override
                public void beforeTextChanged(CharSequence arg0, int arg1,
                                              int arg2, int arg3) {
                    // TODO Auto-generated method stub
     
                }
     
                @Override
                public void afterTextChanged(Editable arg0) {
                    // TODO Auto-generated method stub
                    filtrer();
                }
            });
            //On retourne à l'utilisateur la vue
            return rootView;
        }
     
        public void filtrer() {
            // retourner la chaine saisie par l'utilisateur
            String name = search.getText().toString();
            // créer une nouvelle liste qui va contenir la résultat à afficher
            ArrayList<Food> listFoodNew = new ArrayList<Food>();
     
            for (Food food : listFood) {
                // si le nom du food commence par la chaine saisie , ajouter-le !
                if (food.getName().toLowerCase().toString().startsWith(name)) {
                    listFoodNew.add(food);
                }
            }
            // vider la liste
            lv.setAdapter(null);
            if (listFoodNew.size() == 0) {
                listFoodNew.add(new Food(100, "Pas d'élements.. réessayer !",
                        getResources().getDrawable(R.drawable.ic_action), 0));
            }
            // ajouter la nouvelle liste
            lv.setAdapter(new FoodListAdapter(getActivity().getApplicationContext(), listFoodNew));
            }
    }
    Le code Xml de ma page Home
    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
    <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/LinearLayout1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:background="#ff0c2038">
     
            <EditText
                android:id="@+id/search"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Cherhcer un pays" >
     
            </EditText>
     
            <ListView
                android:id="@+id/listFood"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:divider="@color/list_divider" >
            </ListView>
     
        </LinearLayout>
    Le code java de Food :
    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
    package com.test.urgencecall;
     
    import android.graphics.drawable.Drawable;
     
    /**
     * Created by vuffrayju on 28.04.2015.
     */
    public class Food {
     
        int id;
        String name;
        Drawable picture;
        float price;
     
        public Food(int id, String name, Drawable picture, float price) {
            super();
            this.id = id;
            this.name = name;
            this.picture = picture;
        }
     
        public Food(int i, String listName, Drawable listPicture) {
            super();
        }
     
        public int getId() {
            return id;
        }
     
        public void setId(int id) {
            this.id = id;
        }
     
        public String getName() {
            return name;
        }
     
        public void setName(String name) {
            this.name = name;
        }
     
        public Drawable getPicture() {
            return picture;
        }
     
        public void setPicture(Drawable picture) {
            this.picture = picture;
        }
     
     
     
        @Override
        public String toString() {
            return "Food [id=" + id + ", name=" + name + ", picture=" + picture
                    +"]";
        }
     
    }
    Maintenant de FoodListAdapter
    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
    package com.test.urgencecall;
     
    import android.content.Context;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.animation.Animation;
    import android.view.animation.AnimationUtils;
    import android.widget.BaseAdapter;
    import android.widget.ImageView;
    import android.widget.TextView;
     
     
    import java.util.List;
     
    /**
     * Created by vuffrayju on 28.04.2015.
     */
    public class FoodListAdapter extends BaseAdapter {
     
        private List<Food> listFood = null;
        LayoutInflater layoutInflater;
        Context context;
        private int lastPosition = -1;
     
        // constructeur
        public FoodListAdapter(Context context, List<Food> listFood) {
            this.listFood = listFood;
            layoutInflater = LayoutInflater.from(context);
            this.listFood = listFood;
            this.context = context;
     
        }
     
        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return listFood.size();
        }
     
        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return listFood.get(position);
        }
     
        @Override
        public long getItemId(int arg0) {
            // TODO Auto-generated method stub
            return arg0;
        }
     
        static class ViewHolder {
            TextView nomView;
            ImageView pictureView;
     
        }
     
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
     
            if (convertView == null) {
                convertView = layoutInflater.inflate(R.layout.food_row, null);
                holder = new ViewHolder();
                // initialisation des vues
                holder.nomView = (TextView) convertView.findViewById(R.id.name);
                holder.pictureView = (ImageView) convertView.findViewById(R.id.picture);
     
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            // affchier les données convenablement dans leurs positions
            holder.nomView.setText(listFood.get(position).getName());
            holder.pictureView.setBackgroundDrawable(listFood.get(position)
                    .getPicture());
     
            // changer R.anim.ton_effet
            Animation animation = AnimationUtils.loadAnimation(context,
                    (position > lastPosition) ? R.anim.up_from_bottom : R.anim.up_from_bottom);
     
            convertView.startAnimation(animation);
            lastPosition = position;
            return convertView;
     
        }
    }
    Maintenant le code XML de FoodRow
    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
    <?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="wrap_content"
        android:orientation="horizontal"
        android:padding="5dip"
        android:background="#ff0b1e34">
     
        <LinearLayout
            android:id="@+id/thumbnail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginRight="5dip"
            android:padding="3dip" >
     
            <ImageView
                android:id="@+id/picture"
                android:layout_width="50dip"
                android:layout_height="50dip" />
        </LinearLayout>
     
        <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="name"
            android:textColor="#FFFF"
            android:textSize="20dip"
            android:typeface="sans"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true" />
     
     
     
    </RelativeLayout>
    Voilà un site pour voir le fonctionnement de mon application : https://appetize.io/app/85pbz7aqkmcxkent3rgmzcfcbm

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    179
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2006
    Messages : 179
    Par défaut
    tu as modifié quoi comme code? parce que si tu veux qu'on t'aide faudra être plus précis

  3. #3
    Membre averti
    Homme Profil pro
    élève
    Inscrit en
    Mars 2015
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Suisse

    Informations professionnelles :
    Activité : élève
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2015
    Messages : 14
    Par défaut
    Voila le lien du tuto avec le code.
    J'ai enlever le code qui affichait le prix.

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    179
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2006
    Messages : 179
    Par défaut
    t'as aussi le le dump du build? t'es sur eclipse ou Android Studio?

  5. #5
    Membre averti
    Homme Profil pro
    élève
    Inscrit en
    Mars 2015
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Suisse

    Informations professionnelles :
    Activité : élève
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2015
    Messages : 14
    Par défaut
    Je suis sur android studio

  6. #6
    Membre averti
    Homme Profil pro
    élève
    Inscrit en
    Mars 2015
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Suisse

    Informations professionnelles :
    Activité : élève
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2015
    Messages : 14
    Par défaut
    J'avais une erreur dans le Food.java mais maintenant je n'arrive pas à faire que lorsqu'on sélectionne un pays que l'on change d'activité, je ne sais pas si tu peux m'aider.

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

Discussions similaires

  1. [CKEditor] Rien ne s'affiche
    Par Seth77 dans le forum Bibliothèques & Frameworks
    Réponses: 13
    Dernier message: 28/04/2006, 13h40
  2. [MySQL] Probleme dans ma rrequete rien ne s'affiche
    Par pod1978 dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 31/03/2006, 01h49
  3. [Display lists] Rien ne s'affiche !!!
    Par guepe dans le forum OpenGL
    Réponses: 13
    Dernier message: 06/03/2006, 12h31
  4. [Eclipse3.1] Plus rien ne s'affiche dans ma console !
    Par tnodev dans le forum Eclipse Java
    Réponses: 4
    Dernier message: 12/10/2005, 12h05
  5. [JAVASCRIPT] Rien ne s'affiche lors d'une pause
    Par stephane93fr dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 26/05/2005, 15h38

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