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 :

temps trop long


Sujet :

Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    178
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 178
    Par défaut temps trop long
    bonjour;
    j'ai un fichier de 1.23 Mo a mettre dans un textview qui met plus de 5 minutes a s'afficher.voici mon 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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    t="Recherche"
                android:ems="10"
                android:id="@+id/editText" />
     
            <CheckBox
                android:text="Mot entier"
                android:layout_width="75dp"
                android:layout_height="wrap_content"
                android:id="@+id/cb"
                android:checked="false" />
     
            <Button
                android:text="Executer"
                android:background="@drawable/buttoncolor"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/button" />
     
        </LinearLayout>
     
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
     
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >
     
                <TextView
                    android:text="Attendez la fin du chargement"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="#000000"
                    android:layout_gravity="fill_vertical"
                    android:id="@+id/textView2" />
            </LinearLayout>
        </ScrollView>
     
    </LinearLayout>
    avez vous une idée pour réduire le temps d'affichage

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    178
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 178
    Par défaut
    mauvaise copie de XML voici la bonne version
    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
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">
     
        <TextView
            android:id="@+id/textView"
            android:text="database"
            android:background="#00ff00"
            android:layout_width="match_parent"
            android:layout_height="17dp" />
     
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
     
            <EditText
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:inputType="text"
                android:hint="Recherche"
                android:ems="10"
                android:id="@+id/editText" />
     
            <CheckBox
                android:text="Mot entier"
                android:layout_width="75dp"
                android:layout_height="wrap_content"
                android:id="@+id/cb"
                android:checked="false" />
     
            <Button
                android:text="Executer"
                android:background="@drawable/buttoncolor"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/button" />
     
        </LinearLayout>
     
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
     
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >
     
                <TextView
                    android:text="Attendez la fin du chargement"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="#000000"
                    android:layout_gravity="fill_vertical"
                    android:id="@+id/textView2" />
            </LinearLayout>
        </ScrollView>
     
    </LinearLayout>

  3. #3
    Expert éminent
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Billets dans le blog
    1
    Par défaut
    Salut,


    Je ne pense pas que ton problème viennent de ton XML... mais plutôt de ton code.
    Tu charges comment ce fichier ???


    a++

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    178
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 178
    Par défaut
    merci de ta réponse
    voici mon code pour le chargement
    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
      public String readdb(){
            //large est my file
            large=gettingdb();
     
            try {
                FileChannel fc=new RandomAccessFile(large,"r").getChannel();
                buf=fc.map(FileChannel.MapMode.READ_ONLY,0,fc.size());
                for (int i = 0; i < buf.limit(); i++)
                {
                    sb.append((char)buf.get());
                }
     
            } catch (FileNotFoundException e) {
     
                e.printStackTrace();
            } catch (IOException e) {
     
                e.printStackTrace();
            }
            str=sb.toString();
     
            return str;
        }
    que j'ai trouvé plus rapide qu'en passant par Fileinputstream et bufferedreader

  5. #5
    Expert éminent
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par kapac Voir le message
    que j'ai trouvé plus rapide qu'en passant par Fileinputstream et bufferedreader
    Tu as mesuré le temps d'exécution ?
    Parce que je ne vois pas trop d'intérêt à utiliser un ByteBuffer surtout si c'est pour faire une lecture byte par byte...


    Au passage attention à ton code :
    • Où sont définie les variables ? Il n'y a pas de raison de les déclarer en dehors de la méthode.
    • Tu ne libères pas les ressources ! Il manque un close() ou un try-with-ressource !
    • Tu n'utilises pas de charset et utilise un cast en char qui pourrait te poser problème en dehors des caractères ASCII.



    a++

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    178
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 178
    Par défaut
    je n'avais pas mesuré le temps de chargement ;je pensais que le temps était celui du chargement et non le temps de l'affichage
    compte tenu de tes remarques je suis revenu a ce nouveau code pour m'apercevoir que le temps de chargement de str est tres rapide mais le temps d'affichage est d'environ 30 sec.nouveau code
    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
     public String readdb(){
            File large;
            StringBuilder sb=new StringBuilder();
            large=gettingdb();
     
            try {
                BufferedReader buf=new BufferedReader(new FileReader(large));
                String line;
                      //=fc.map(FileChannel.MapMode.READ_ONLY,0,fc.size());
               while((line=buf.readLine())!=null)
                {
                    sb.append(line);
                    sb.append("\n");
                }
                    buf.close();
            } catch (FileNotFoundException e) {
     
                e.printStackTrace();
            } catch (IOException e) {
     
                e.printStackTrace();
            }
            str=sb.toString();
     
            return str;
        }
    j'ai un autre probleme les é,à...ne sont pas reconnus dans mon str
    est ce en rapport avec ta 3 eme remarque?

  7. #7
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    178
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 178
    Par défaut
    nouveau code qui résoud le probleme des accents
    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
     public String readdb(){
            File large;
            FileInputStream fis=null;
            StringBuilder sb=new StringBuilder();
            large=gettingdb();
                  try {
                fis=new FileInputStream (large);
                BufferedReader buf=new BufferedReader(new InputStreamReader(fis,"ISO-8859-1"));
                String line;
                      //=fc.map(FileChannel.MapMode.READ_ONLY,0,fc.size());
               while((line=buf.readLine())!=null)
                {
                    sb.append(line);
                    sb.append("\n");
                }
                    buf.close();
            } catch (FileNotFoundException e) {
     
                e.printStackTrace();
            } catch (IOException e) {
     
                e.printStackTrace();
            }
            str=sb.toString();
     
            return str;
        }

  8. #8
    Expert éminent
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par kapac Voir le message
    je n'avais pas mesuré le temps de chargement ;je pensais que le temps était celui du chargement et non le temps de l'affichage
    compte tenu de tes remarques je suis revenu a ce nouveau code pour m'apercevoir que le temps de chargement de str est tres rapide mais le temps d'affichage est d'environ 30 sec.nouveau code
    Il faudrait que tu identifies dans ton code ce qui prend 30 secondes.

    Que fais-tu de ce texte après l'appel à readdb() ?


    Citation Envoyé par kapac Voir le message
    j'ai un autre probleme les é,à...ne sont pas reconnus dans mon str
    est ce en rapport avec ta 3 eme remarque?
    Oui


    a++

Discussions similaires

  1. temps trop long pour changer de dossier
    Par Guslain dans le forum Outlook
    Réponses: 1
    Dernier message: 12/01/2011, 13h29
  2. [VB6]Message d'erreur si le temps d'exécution est trop long
    Par Asdorve dans le forum VB 6 et antérieur
    Réponses: 16
    Dernier message: 14/09/2006, 16h43
  3. [MySQL] Problème temps d'éxécution trop long
    Par Yo. dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 13/06/2006, 14h55
  4. temp de réponse trop long
    Par maxidoove dans le forum Langage SQL
    Réponses: 6
    Dernier message: 27/10/2005, 18h24
  5. Arrêter un prog si temps de connexion trop long
    Par jakouz dans le forum Langage
    Réponses: 4
    Dernier message: 22/10/2002, 18h28

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