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 :

Rafraîchir une listview automatiquement lors d'une modification de base


Sujet :

Composants graphiques Android

  1. #1
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2018
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mars 2018
    Messages : 5
    Points : 3
    Points
    3
    Par défaut Rafraîchir une listview automatiquement lors d'une modification de base
    lorsque j'ajoute une chose dans base de donnée mysql
    je veux voir dans la listview automatiquement
    dans mon exemple , je ferme l'application puis ouvrier pour voir la chose qui ajouté
    svp donner moi une solution
    et merci infiniment
    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
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
     package com.example.lenovo.pfe.tablayoutfragment;
     
    import android.content.Context;
    import android.graphics.Typeface;
    import android.net.Uri;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentTransaction;
    import android.support.v4.widget.SwipeRefreshLayout;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ImageView;
    import android.widget.ListView;
    import android.widget.ProgressBar;
    import android.widget.TextView;
    import android.widget.Toast;
     
    import com.example.lenovo.pfe.Itemetitemadapter.Evenementitem.EvenementAdapter;
    import com.example.lenovo.pfe.Itemetitemadapter.Evenementitem.EvenementItem;
    import com.example.lenovo.pfe.R;
    import com.example.lenovo.pfe.httpwebserviceverification.httpwebservice;
     
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
     
    import java.util.ArrayList;
    import java.util.List;
     
     
    public class Evenementfragment extends Fragment {
        TextView txtmen;
        ProgressBar progressBar;
        ListView listview;
        Typeface type;
        ImageView img;
        String affichage = "http://192.168.100.50/projet/afficherevenement.php";
        public Evenementfragment() {
        }
     
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
     
        }
     
        @Override
        public View onCreateView(LayoutInflater inflater, final ViewGroup container,
                                 Bundle savedInstanceState) {
     
            View rootView = inflater.inflate(R.layout.fragment_evenementfragment, container, false);
            txtmen = (TextView) rootView.findViewById(R.id.textmenu);
            img = (ImageView) rootView.findViewById(R.id.imgmenu);
            progressBar = (ProgressBar) rootView.findViewById(R.id.ProgressBar1);
            listview = (ListView) rootView.findViewById(R.id.listeve);
            type = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Montserrat-Light.otf");
            txtmen.setTypeface(type);
            new ParsJsonDataEvenemt(container.getContext()).execute();
     
            return rootView;
        }
     
     
        private class ParsJsonDataEvenemt extends AsyncTask<Void, Void, Void> {
            public Context context;
            String FinalJSonResult;
            List<EvenementItem> eveitem;
     
            public ParsJsonDataEvenemt(Context context) {
                this.context = context;
            }
            @Override
            protected void onPreExecute() {
     
                super.onPreExecute();
            }
     
            @Override
            protected Void doInBackground(Void... voids) {
                httpwebservice htp = new httpwebservice(affichage);
                try {
                    htp.ExecutePostRequest();
                    if (htp.getResponseCode() == 200) {
                        FinalJSonResult = htp.getResponse();
                        if (FinalJSonResult != null) {
                            JSONArray jsonArray = null;
                            try {
                                jsonArray = new JSONArray(FinalJSonResult);
                                JSONObject jsonObject;
                                EvenementItem evitem;
                                eveitem = new ArrayList<EvenementItem>();
                                for (int i = 0; i < jsonArray.length(); i++) {
                                    evitem = new EvenementItem();
                                    jsonObject = jsonArray.getJSONObject(i);
                                    evitem.setNomevenement(jsonObject.getString("nomevenement"));
                                    evitem.setTypeevenement(jsonObject.getString("typeevenement"));
                                    evitem.setImportanceevenement(jsonObject.getString("importenceevenement"));
                                    evitem.setDateevenement(jsonObject.getString("dateevenement"));
                                    evitem.setHeurevenement(jsonObject.getString("heureevenement"));
                                    evitem.setDescevenement(jsonObject.getString("descriptionevenement"));
                                    eveitem.add(evitem);
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        } else {
     
                            Toast.makeText(context, htp.getErrorMessage(), Toast.LENGTH_SHORT).show();
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
            protected void onPostExecute(Void result) {
                if (eveitem != null) {
                    progressBar.setVisibility(View.GONE);
                    listview.setVisibility(View.VISIBLE);
                    EvenementAdapter adapter = new EvenementAdapter(eveitem, context);
                    adapter.notifyDataSetChanged();
                    listview.setAdapter(adapter);
     
                } else {
                    progressBar.setVisibility(View.GONE);
                    txtmen.setVisibility(View.VISIBLE);
                    img.setVisibility(View.VISIBLE);
                }
            }
        }
    }

  2. #2
    Expert confirmé Avatar de yildiz-online
    Homme Profil pro
    Architecte de domaine
    Inscrit en
    Octobre 2011
    Messages
    1 444
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Architecte de domaine

    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 444
    Points : 4 563
    Points
    4 563
    Par défaut
    De quelle manière ton application est elle notifiée d'une mise à jour de la DB? polling, event?

    Une fois que tu as la réponse à cette question il te suffit de recharger ta page PHP suite à la notification.
    PXL le retro-gaming facile: Essayez-le

    Yildiz-Engine an open-source modular game engine: Website
    Yildiz-Online a 3D MMORTS in alpha: Facebook page / Youtube page

  3. #3
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2018
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mars 2018
    Messages : 5
    Points : 3
    Points
    3
    Par défaut
    Citation Envoyé par yildiz-online Voir le message
    De quelle manière ton application est elle notifiée d'une mise à jour de la DB? polling, event?

    Une fois que tu as la réponse à cette question il te suffit de recharger ta page PHP suite à la notification.
    Svp comment je recharger php suite a la notification

  4. #4
    Expert confirmé Avatar de yildiz-online
    Homme Profil pro
    Architecte de domaine
    Inscrit en
    Octobre 2011
    Messages
    1 444
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Architecte de domaine

    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 444
    Points : 4 563
    Points
    4 563
    Par défaut
    de la même manière que tu l'as chargé la première fois.
    PXL le retro-gaming facile: Essayez-le

    Yildiz-Engine an open-source modular game engine: Website
    Yildiz-Online a 3D MMORTS in alpha: Facebook page / Youtube page

Discussions similaires

  1. j'ai une problème dans vista
    Par belkacembilgate dans le forum Installation
    Réponses: 1
    Dernier message: 26/04/2007, 14h58
  2. j'ai une probléme avec le map
    Par killer_instinct dans le forum C++
    Réponses: 4
    Dernier message: 10/12/2006, 14h58
  3. une probléme pour le relation
    Par bagkhk963 dans le forum Access
    Réponses: 4
    Dernier message: 25/05/2006, 22h47
  4. une probléme pour le relation
    Par bagkhk963 dans le forum Access
    Réponses: 3
    Dernier message: 23/05/2006, 10h23

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