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 :

Comment créer une GridView à partir d'une ListView ?


Sujet :

Composants graphiques Android

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 104
    Points : 66
    Points
    66
    Par défaut Comment créer une GridView à partir d'une ListView ?
    Bonjour à tous!
    Voilà j'aimerai savoir comment créer une GridView à partir de mon affichage ListView.
    Je m'explique :
    Mon application est basé sur un explorateur de fichiers internes et externes du mobile.

    L'affichage de base de celle-ci est une ListView.
    Je voudrais qu'à l'aide d'une option dans mes préférences l'utilisateur switch vers un affichage en GridView.(ce que je voudrais créer mais avec les fichiers internes et externes du mobile)

    Merci pour vos réponses!

  2. #2
    Rédacteur
    Avatar de MrDuChnok
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2002
    Messages
    2 112
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Juin 2002
    Messages : 2 112
    Points : 4 240
    Points
    4 240
    Par défaut
    Salut,

    Et qu'est ce que tu n'arrives pas à faire précisément ?
    Si vous jugez mon post utile dans la résolution de votre problème, n'hésitez pas à utiliser le système de vote afin d'améliorer la qualité du forum

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 104
    Points : 66
    Points
    66
    Par défaut
    Merci d'avoir pris un peu de ton temps pour répondre à ma question.

    Voilà, mon app liste des fichiers internes et externes au mobile.
    Le tuto GridView de android developers, ne renvoie que sur des images ajoutées dans le dossier "drawable" mais moi je voudrais que celà affiche tous les dossier et fichiers du mobile qu'ils soient internes ou externes.

    Pour l'affichage des fichiers ou dossier c'est bon mais c'est pour créer l'affichage en GridView que je coince, je n'arrive pas à récupérer les dossier et fichiers.

    Merci pour ton aide !

  4. #4
    Rédacteur
    Avatar de MrDuChnok
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2002
    Messages
    2 112
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Juin 2002
    Messages : 2 112
    Points : 4 240
    Points
    4 240
    Par défaut
    Voici comment récupérer la liste des "racines" de son système :
    http://java.developpez.com/faq/java/...FICHIER_racine

    Et ensuite comment parcourir les dossiers / fichiers :
    http://java.developpez.com/faq/java/...scence_fichier

    Une fois que tu auras tes listes, tu pourras gérer l'affichage comme bon te semble, via un système d'icônes (comme dans l'exemple fourni par le site des développeur Android)
    Si vous jugez mon post utile dans la résolution de votre problème, n'hésitez pas à utiliser le système de vote afin d'améliorer la qualité du forum

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 104
    Points : 66
    Points
    66
    Par défaut
    Merci bien pour le liens!

    Pour les listes, voilà les captures d'écran des différents listages que j'ai obtenu avec des icônes persos pour les différents types de fichiers en pièces jointes.
    Images attachées Images attachées    

  6. #6
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 104
    Points : 66
    Points
    66
    Par défaut
    Voici le code de mon activity principale associé à ces différentes vues : (ça doit être la pagaille surement )


    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
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
     import java.io.DataOutputStream;
    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;
     
    import android.app.AlertDialog;
    import android.app.ListActivity;
    import android.content.DialogInterface;
    import android.content.DialogInterface.OnClickListener;
    import android.content.Intent;
    import android.graphics.drawable.Drawable;
    import android.net.Uri;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.ContextMenu;
    import android.view.ContextMenu.ContextMenuInfo;
    import android.view.LayoutInflater;
    import android.view.Menu;
    import android.view.MenuInflater;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.AdapterView.AdapterContextMenuInfo;
    import android.widget.EditText;
    import android.widget.ListView;
    import android.widget.Toast;
     
     
    public class Logiciel extends ListActivity {
     
    	public enum DISPLAYMODE{ ABSOLUTE, RELATIVE; }
     
        private final DISPLAYMODE displayMode = DISPLAYMODE.RELATIVE;
        private List<AffichageListText> directoryEntries = new ArrayList<AffichageListText>();
        private File currentDirectory = new File("");
     
        public boolean can_su;
        public String su_bin_file;
     
    public Logiciel() {
                this.can_su = true;
                this.su_bin_file = "/system/xbin/su";
                if (this.Run("echo"))
                        return;
                this.su_bin_file = "/system/bin/su";
                if (this.Run("echo"))
                        return;
                this.su_bin_file = "";
                this.can_su = false;
     
        }
     
    public boolean Run(String command) {
        DataOutputStream os = null;
        try {
                        Process process = Runtime.getRuntime().exec(this.su_bin_file);
                        os = new DataOutputStream(process.getOutputStream());
                        os.writeBytes(command + "\n");
                        os.flush();
                        os.writeBytes("exit\n");
                        os.flush();
                        process.waitFor();                    
                        return true;
                } catch (IOException e) {
                        e.printStackTrace();
     
                } catch (InterruptedException e) {
                        e.printStackTrace();
        }            
        return false;
        }
     
    public void onCreate(Bundle saveInstanceState) {
        super.onCreate(saveInstanceState);
        registerForContextMenu(getListView());
        browseToRoot();
     
    }
     
    private void browseToRoot() {
        browseTo(new File("/"));
     
    }
     
    private void upOneLevel(){
        if(this.currentDirectory.getParent() != null)
                this.browseTo(this.currentDirectory.getParentFile());
     
    }
     
    private void browseTo(final File dir){
     
        if(this.displayMode == DISPLAYMODE.RELATIVE)
                this.setTitle(dir.getAbsolutePath());
     
        if (dir.isDirectory()){
                this.currentDirectory = dir;
                fill(dir.listFiles());
     
        }else{
                OnClickListener okButtonListener = new OnClickListener(){
     
    public void onClick(DialogInterface arg0, int arg1) {
                Logiciel.this.openFile(dir);
     
    }
    };
     
                OnClickListener cancelButtonListener = new OnClickListener(){
     
    public void onClick(DialogInterface arg0, int arg1) {
     
    }
    };
     
    			new AlertDialog.Builder(this)
                .setTitle("Question")            
                .setMessage("Voulez-vous ouvrir ce fichier ?")
                .setPositiveButton("OK", okButtonListener)
                .setNegativeButton("Annuler", cancelButtonListener)
                .show();
    }
    }
     
    private void openFile(File f)
     
    {
     
        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setAction(android.content.Intent.ACTION_VIEW);
     
        String type = getMIMEType(f);
        intent.setDataAndType(Uri.fromFile(f), type);
     
        startActivity(intent);
     
    }
     
    private String getMIMEType(File f)
     
    {
     
        String end = f.getName().substring(f.getName().lastIndexOf(".")+1, f.getName().length()).toLowerCase();
        String type = "";
     
        if(end.equals("mp3") || end.equals("wma") || end.equals("ogg")) type = "audio";
     
        else if(end.equals("avi") || end.equals("divx") || end.equals("mkv") || end.equals("mp4") || end.equals("mpeg") || end.equals("wav") || end.equals("flv") || end.equals("wmv") || end.equals("3gp")) type = "video";
     
        else if(end.equals("jpg") || end.equals("gif") || end.equals("png") || end.equals("jpeg") || end.equals("bmp")) type = "image";    
     
        else if(end.equals("txt") || end.equals("php") || end.equals("html")) type = "text";
     
        else if(end.equals("apk") || end.equals("pdf") || end.equals("rtf") || end.equals("jar")|| end.equals("zip") || end.equals("rar") || end.equals("torrent")) type = "application";
     
        type += "/*";
     
        return type;
     
    }
     
    private void fill(File[] files) {
     
        this.directoryEntries.clear();
     
        if(this.currentDirectory.getParent() != null)
                this.directoryEntries.add(new AffichageListText(getString(R.string.retour),getResources().getDrawable(R.drawable.retour)));
     
        Drawable currentIcon = null;
        for (File currentFile : files){
        if (currentFile.isDirectory()) {
           currentIcon = getResources().getDrawable(R.drawable.folder);
     
        }else{
     
           String fileName = currentFile.getName();
     
     
                        								// Icônes des fichiers Images...
                        if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingImagePNG))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.png);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingImageJPEG))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.jpeg);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingImageJPG))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.jpg);    
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingImageBMP))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.bmp);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingImageGIF))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.gif);    
     
     
     
                            							// Icônes des fichiers WEB...                            
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingWebTextPDF))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.pdf);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingWebTextHTML))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.html);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingWebTextPHP))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.php);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingWebTextTORRENT))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.torrent);
     
     
     
                            							// Icônes des fichiers Archives...                                
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingPackageRAR))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.rar);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingPackageZIP))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.zip);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingPackageISO))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.iso);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingPackageJAR))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.jar);
     
     
     
                            							// Icônes des fichiers Audios...                                
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingAudioMP3))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.mp3);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingAudioWMA))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.wma);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingAudioOGG))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.ogg);    
     
     
     
                            							// Icônes des fichiers Vidéos...                                
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideoAVI))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.avi);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideoDIVX))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.divx);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideoMKV))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.mkv);    
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideoMP4))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.mp4);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideoMPEG))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.mpeg);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideoWAV))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.wav);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideoFLV))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.flv);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideoWMV))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.wmv);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideo3GP))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.gp3);    
     
     
     
                            							// Icônes des fichiers Textes...                            
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingTextRTF))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.rtf);
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingTextTXT))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.txt);    
     
                        }else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingTextAPK))){                                        
                            currentIcon = getResources().getDrawable(R.drawable.apk);
     
     
                        }else{                                       
                        	currentIcon = getResources().getDrawable(R.drawable.unknow);
     
     
    }                              
    }
     
                switch (this.displayMode) {
                        case ABSOLUTE:
     
                                this.directoryEntries.add(new AffichageListText(currentFile.getPath(), currentIcon));
                                break;
     
                        case RELATIVE:
     
                                int currentPathStringLenght = this.currentDirectory.getAbsolutePath().length();                            
                                this.directoryEntries.add(new AffichageListText(currentFile.getAbsolutePath().substring(currentPathStringLenght),currentIcon));
                                break;
     
    }
    }
     
        Collections.sort(this.directoryEntries);
     
        AffichageListAdapter itla = new AffichageListAdapter(this);
        itla.setListItems(this.directoryEntries);              
        this.setListAdapter(itla);
     
    }
     
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
     
        String selectedFileString = this.directoryEntries.get(position).getText();
        if (selectedFileString.equals(getString(R.string.current_dir))) {
     
                this.browseTo(this.currentDirectory);
     
        } else if (selectedFileString.equals(getString(R.string.retour))) {
                this.upOneLevel();
     
        } else {
                File clickedFile = null;
                switch (this.displayMode) {
                        case RELATIVE:
                                clickedFile = new File(this.currentDirectory
                                                .getAbsolutePath()
                                                + this.directoryEntries.get(position).getText());
                                break;
     
                        case ABSOLUTE:
                                clickedFile = new File(this.directoryEntries.get(position).getText());
                                break;
     
    }
     
                if (clickedFile != null)
     
                	Log.d("Hadès™ Files Explorer", "File " + clickedFile + " exists? " +
     
                            clickedFile.exists());
                        this.browseTo(clickedFile);
     
    }
    }
     
    private boolean checkEndsWithInStringArray(String checkItsEnd,
                 String[] fileEndings){
    				for(String aEnd : fileEndings){
    					if(checkItsEnd.endsWith(aEnd))
    						return true;
    }
    return false;
    }
     
    public boolean onCreateOptionsMenu(Menu menu) {
     
    	MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menugeneral, menu);
        return true;
     
    }
     
    public boolean onOptionsItemSelected(MenuItem item) {
     
        switch (item.getItemId()) {
        case R.id.quitter:
        	Toast.makeText(Logiciel.this, "Quitter", Toast.LENGTH_SHORT).show();
            finish();
            return true;
     
     
     
     
     
        case R.id.plus:
     
        	Toast.makeText(Logiciel.this, "Plus", Toast.LENGTH_SHORT).show();
        	return true;
     
        case R.id.apropos:
     
      	  LayoutInflater factory = LayoutInflater.from(this);
            final View alertDialogView = factory.inflate(R.layout.alert_apropos, null);
     
            final AlertDialog.Builder adb = new AlertDialog.Builder(this);
     
            adb.setView(alertDialogView);
            adb.setTitle("A Propos");
            adb.setIcon(R.drawable.hfe1);
            adb.setNeutralButton("Fermer", null); {
            adb.show();
      };
          	return true;
     
        case R.id.favoris:
     
        	return true;
     
        case R.id.rafraichir:
     
        	return true;
     
     
     
     
     
        case R.id.preferences:            	
        	startActivity(new Intent(this, MesPreferences.class));
        	Toast.makeText(Logiciel.this, "Préférences", Toast.LENGTH_SHORT).show();
        	return true;    	
     
     
     
     
     
        case R.id.option:
        	Toast.makeText(Logiciel.this, "Options", Toast.LENGTH_SHORT).show();
        	return true;
     
        case R.id.applicationsinstallees:
        	startActivity(new Intent(this, ListeAppInstall.class));
        	return true;
     
        case R.id.sdexterne:
        	startActivity(new Intent(this, SDExterne.class));
        	return true;	
     
     
     
     
    	case R.id.nouveau:
        	Toast.makeText(Logiciel.this, "Nouveau", Toast.LENGTH_SHORT).show();
        	return true;
     
        case R.id.dossier:
     
        	return true;
     
        case R.id.fichier:
     
        	return true;
     
    }	
     
    {
        return false;
    }
    }
     
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
      super.onCreateContextMenu(menu, v, menuInfo);
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.menucontextuel, menu);
    }
     
    @Override
    public boolean onContextItemSelected(MenuItem item) {
     
      AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
     
      switch (item.getItemId()) {
      case R.id.couper:
     
    	  	return true;
     
      case R.id.copier:
     
    	  	return true;
     
      case R.id.coller:
     
    	    return true;
     
      case R.id.renommer:
     
    	  LayoutInflater factory = LayoutInflater.from(this);
          final View alertDialogView = factory.inflate(R.layout.alert_renommer, null);
     
          AlertDialog.Builder adb = new AlertDialog.Builder(this);
     
          adb.setView(alertDialogView);
          adb.setTitle("Renommer");
          adb.setIcon(R.drawable.hfe1);
          adb.setPositiveButton("OK", new DialogInterface.OnClickListener() {
     
     
    public void onClick(DialogInterface dialog, int which) {
     
              	EditText et = (EditText)alertDialogView.findViewById(R.id.EditText1);
     
              	Toast.makeText(Logiciel.this, et.getText(), Toast.LENGTH_SHORT).show();
            } });
     
          adb.setNegativeButton("Annuler", new DialogInterface.OnClickListener() {
     
    public void onClick(DialogInterface dialog, int which) {
     
              	return;
            } });
          adb.show();
        return false;
     
      case R.id.supprimer:
     
    	  new AlertDialog.Builder(this)
    	  .setIcon(R.drawable.hfe1)
          .setTitle("Confirmation")            
          .setMessage("Voulez-vous vraiment supprimer ?")
          .setPositiveButton("OK", null)
          .setNegativeButton("Annuler",null)
          .show();
    		return true;
     
      case R.id.proprietes:
     
    		return true;     
      default:
     
        return super.onContextItemSelected(item);
      }
     
    }
    }

    Celui de mon Adapter :

    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
    import java.util.ArrayList;
    import java.util.List;
     
    import android.content.Context;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
     
     
    public class AffichageListAdapter extends BaseAdapter {
     
     
            private Context mContext;
     
            private List<AffichageListText> mItems = new ArrayList<AffichageListText>();
     
            public AffichageListAdapter(Context context) {
                    mContext = context;
            }
     
            public void addItem(AffichageListText it) { mItems.add(it); }
     
            public void setListItems(List<AffichageListText> lit) { mItems = lit; }
     
            public int getCount() { return mItems.size(); }
     
            public Object getItem(int position) { return mItems.get(position); }
     
            public boolean areAllItemsSelectable() { return false; }
     
            public boolean isSelectable(int position) {
                    try{
                            return mItems.get(position).isSelectable();
                    }catch (IndexOutOfBoundsException aioobe){
                            return super.isEnabled(position);
                    }
            }
     
            public long getItemId(int position) {
                    return position;
            }
     
     
            public View getView(int position, View convertView, ViewGroup parent) {
                    AffichageListTextView btv;
                    if (convertView == null) {
                            btv = new AffichageListTextView(mContext, mItems.get(position));
                    } else { 
     
                            btv = (AffichageListTextView) convertView;
                            btv.setText(mItems.get(position).getText());
                            btv.setIcon(mItems.get(position).getIcon());
                    }
                    return btv;
            }
    }
    Voilà mais je n'arrive pas à utiliser le GridView

    Alors si vous pouviez m'éclairer svp...

  7. #7
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    Bonjour,

    Tu n'arrives pas à faire quoi exactement sur la gridview ?
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  8. #8
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 104
    Points : 66
    Points
    66
    Par défaut
    Bonjour

    Je voudrais que ce soit les fichiers listés (plus haut en miniatures) qui soient sous formes de GridView et je ne sais pas comment récupérer ces informations pour les intégrer à ma GridView

  9. #9
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    http://developer.android.com/guide/t...-gridview.html

    Remplace le contenu de la variable mThumbIds par la liste de fichier (String nom de fichier ou une classe comportant les informations que tu veux sauvegarder).
    C'est la même chose que pour la listview.
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  10. #10
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 104
    Points : 66
    Points
    66
    Par défaut
    donc par exemple

    private Integer[] mThumbIds = (String, Logiciel.class) { ??????

  11. #11
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    SI je reprends ton code il suffit que tu garde l'adapter et que tu l'appliques sur ta gridview .

    Rempli jutse ta variable mItems par l'ensemble de fichier que tu veux présent dans ta gridview .

    C'est tout .

    Donc soit mThumbIds dans l'exemple que je t'ai donné serait directoryEntries dans ton code.

    Exemple dans le OnCreate()

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
        Collections.sort(this.directoryEntries);
        GridView gridview = (GridView) findViewById(R.id.gridview);
        AffichageListAdapter itla = new AffichageListAdapter(this);
        gridview.setListItems(this.directoryEntries);              
        gridview.setListAdapter(itla);
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  12. #12
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 104
    Points : 66
    Points
    66
    Par défaut
    Bon et bien je dois vraiment être idiot mais je n'y arrive pas

    J'ai eu un affichage comme celui de la miniature
    Images attachées Images attachées  

  13. #13
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    Poste moi ton code et dis mois ou tu veux mettre la gridView
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  14. #14
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 104
    Points : 66
    Points
    66
    Par défaut
    Citation Envoyé par Feanorin Voir le message
    Poste moi ton code et dis mois ou tu veux mettre la gridView
    Justement je voudrai que tout l'affichage soit en GridView à la place d'être en ListView.

    Quel code veux-tu?

  15. #15
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    Remplace

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
        AffichageListAdapter itla = new AffichageListAdapter(this);
        itla.setListItems(this.directoryEntries);              
        this.setListAdapter(itla);
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
        Collections.sort(this.directoryEntries);
        gridview = (GridView) findViewById(R.id.gridview);
        AffichageListAdapter itla = new AffichageListAdapter(this);
        gridview.setListItems(this.directoryEntries);              
        gridview.setAdapter((ListAdapter)itla);
    Déclare en plus dans comme menbre la gridview

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    public GridView gridview;
    Dans le onCreate() avant l'appel du browseto et après le SetContent

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    gridview = (GridView) findViewbyId(R.id.gridview);
    Il te manqueras plus que le layout à modifier
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    <?xml version="1.0" encoding="utf-8"?>
    <GridView xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/gridview"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:columnWidth="90dp"
        android:numColumns="auto_fit"
        android:verticalSpacing="10dp"
        android:horizontalSpacing="10dp"
        android:stretchMode="columnWidth"
        android:gravity="center"
    />
    au lieu de la listview que tu as en ce moment .
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  16. #16
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 104
    Points : 66
    Points
    66
    Par défaut
    Bon alors maintenant après modifications la première partie est comme cela :




    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
     
     
        public class Logiciel extends ListActivity {
     
    	public enum DISPLAYMODE{ ABSOLUTE, RELATIVE; }
     
        private final DISPLAYMODE displayMode = DISPLAYMODE.RELATIVE;
        private List<AffichageListText> directoryEntries = new ArrayList<AffichageListText>();
        private File currentDirectory = new File("");
     
        public boolean can_su;
        public String su_bin_file;
        public GridView gridview;
     
    public Logiciel() {
                this.can_su = true;
                this.su_bin_file = "/system/xbin/su";
                if (this.Run("echo"))
                        return;
                this.su_bin_file = "/system/bin/su";
                if (this.Run("echo"))
                        return;
                this.su_bin_file = "";
                this.can_su = false;
     
        }
     
    public boolean Run(String command) {
        DataOutputStream os = null;
        try {
                        Process process = Runtime.getRuntime().exec(this.su_bin_file);
                        os = new DataOutputStream(process.getOutputStream());
                        os.writeBytes(command + "\n");
                        os.flush();
                        os.writeBytes("exit\n");
                        os.flush();
                        process.waitFor();                    
                        return true;
                } catch (IOException e) {
                        e.printStackTrace();
     
                } catch (InterruptedException e) {
                        e.printStackTrace();
        }            
        return false;
        }
     
    public void onCreate(Bundle saveInstanceState) {
        super.onCreate(saveInstanceState);
        this.setContentView(R.layout.logiciel);
     
        gridview = (GridView) findViewById(R.id.gridview);
        registerForContextMenu(getListView());
     
        browseToRoot();
     
    }
     
    }

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Collections.sort(this.directoryEntries);
        gridview = (GridView) findViewById(R.id.gridview);
        AffichageListAdapter itla = new AffichageListAdapter(this);
        gridview.setListItems(this.directoryEntries);              
        gridview.setAdapter((ListAdapter)itla);
     
    }
    J'ai une erreur sur le gridview.setListItems(this.directoryEntries);
    Il me demande add cast to 'gridview' ce qui ne résout pas l'erreur mais qui l'étends comme suit : ((AffichageListAdapter) gridview).setListItems(this.directoryEntries);

  17. #17
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    Je suis allé un peu vite

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Collections.sort(this.directoryEntries);
        gridview = (GridView) findViewById(R.id.gridview);
        AffichageListAdapter itla = new AffichageListAdapter(this);
        itla.setListItems(this.directoryEntries);              
        gridview.setAdapter((ListAdapter)itla);
        
    }
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  18. #18
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 104
    Points : 66
    Points
    66
    Par défaut
    Ok merci beaucoup.

    Par contre, j'ai un force close :

    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
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258): FATAL EXCEPTION: main
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hades_files_explorer/com.hades_files_explorer.Logiciel}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at android.os.Handler.dispatchMessage(Handler.java:99)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at android.os.Looper.loop(Looper.java:123)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at android.app.ActivityThread.main(ActivityThread.java:4627)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at java.lang.reflect.Method.invokeNative(Native Method)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at java.lang.reflect.Method.invoke(Method.java:521)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at dalvik.system.NativeStart.main(Native Method)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at android.app.ListActivity.onContentChanged(ListActivity.java:245)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at android.app.Activity.setContentView(Activity.java:1647)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at com.hades_files_explorer.Logiciel.onCreate(Logiciel.java:81)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
    11-22 19:51:48.552: ERROR/AndroidRuntime(14258):     ... 11 more
    Alors d'après ce que je peux comprendre, cela vient du fait que je n'ai pas de ListView avec l'attribut android.R.id.list

    Mais si je veux que ce soit en GridView pourquoi j'ai cette erreur ??

  19. #19
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    OUbliez le plus important

    T'as classe n'est plus une ListActivity mais une Activity simple
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  20. #20
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    104
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 104
    Points : 66
    Points
    66
    Par défaut
    Oui c'est logique..

    Maintenant c'est dans ma ligne ci-dessous :

    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
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
    
        String selectedFileString = this.directoryEntries.get(position).getText();
        if (selectedFileString.equals(getString(R.string.current_dir))) {
                
                this.browseTo(this.currentDirectory);
                
        } else if (selectedFileString.equals(getString(R.string.retour))) {
                this.upOneLevel();
                
        } else {
                File clickedFile = null;
                switch (this.displayMode) {
                        case RELATIVE:
                                clickedFile = new File(this.currentDirectory
                                                .getAbsolutePath()
                                                + this.directoryEntries.get(position).getText());
                                break;
                                
                        case ABSOLUTE:
                                clickedFile = new File(this.directoryEntries.get(position).getText());
                                break;
                                
    }
                
                if (clickedFile != null)
                	
                	Log.d("Hadès™ Files Explorer", "File " + clickedFile + " exists? " +
                			 
                            clickedFile.exists());
                        this.browseTo(clickedFile);
                
    }
    }
    J'ai modifié le (ListView l, View v, int position, long id) par (GridView g, View v, int position, long id) mais j'ai toujours mon erreur sur le onListItemClick

    J'ai bien compris que ce n'était plus une liste mais j'ai aucunes suggestions d'Eclipse..


    Edit:
    Alors j'ai modifié le onListItemClick par onSelectedFileString et je n'ai pas de soucis pour lancer l'appli.

    Par contre concernant l'affichage (miniature jointe) il y a comme qui dirait un petit sushi

    Et à la sélection d'un item, plus rien ne se passe.
    Je n'ai plus accès au sous-répertoire ni rien...
    Images attachées Images attachées  

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 3 123 DernièreDernière

Discussions similaires

  1. [Python 2.X] Comment créer un classement à partir d'une liste
    Par samcro7 dans le forum Général Python
    Réponses: 6
    Dernier message: 12/04/2015, 03h18
  2. [XL-2010] Comment créer un formulaire à partir d'une feuille Excel
    Par Denis_67 dans le forum Excel
    Réponses: 2
    Dernier message: 10/06/2014, 11h09
  3. [Artichow] Comment créer un graphe à partir d'une table mysql avec deux colonnes
    Par Amel_B dans le forum Bibliothèques et frameworks
    Réponses: 5
    Dernier message: 24/12/2013, 15h50
  4. Réponses: 1
    Dernier message: 14/07/2008, 11h17
  5. comment créer un rpm à partir d'une lib source
    Par kris1 dans le forum Applications et environnements graphiques
    Réponses: 1
    Dernier message: 06/12/2007, 17h35

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