Populate Android ListView with names of items in asset folder -


i building media player based on elses code. media player plays mp3's asset folder. have added listview media player layout.xml , populate list contents of asset folder. there code in main java takes mp3 name , displays in pop-up. how can information load list instead. ietm in list must correspond track playing.

here java code

 //generate string array represents of files found private string[] gettracks(){     if(type == 0){         try {             string[] temp = getassets().list("");             return temp;         } catch (ioexception e) {             e.printstacktrace();             toast.maketext(getbasecontext(), e.getmessage(), toast.length_long).show();         }     } else if(type == 1){         if(environment.getexternalstoragestate().equals(environment.media_mounted)                  || environment.getexternalstoragestate().equals(environment.media_mounted_read_only)){             path = environment.getexternalstoragepublicdirectory(environment.directory_music);             path2 = environment.getexternalstoragepublicdirectory(environment.directory_pictures);             string[] temp = path.list();             return temp;         } else{             toast.maketext(getbasecontext(), "sd card either mounted elsewhere or unusable", toast.length_long).show();         }     }     return null; }  //adds playable files tracknames list private void addtracks(string[] temp){     if(temp != null){         for(int = 0; < temp.length; i++){             //only accept files have 1 of extensions in extensions array             if(trackchecker(temp[i])){                 tracknames.add(temp[i]);                 trackartworks.add(temp[i].substring(0, temp[i].length()-4));             }         }         toast.maketext(getbasecontext(), "loaded " + integer.tostring(tracknames.size()) + " tracks", toast.length_short).show();     } }  //plays track     private void playtrack(){         if(istuning && track != null){             track.play();             toast.maketext(getbasecontext(), "playing " + tracknames.get(currenttrack).substring(0, tracknames.get(currenttrack).length()-4), toast.length_short).show();         }     } 

and xml

   <listview     android:id="@+id/tracknames"     android:layout_width="match_parent"     android:layout_height="98dp"     android:layout_weight="0.74" > </listview> 

how can populate list? how can using code have?

you need create arrayadapter, or subclass of arrayadapter, add data it, , set in listview.

here example.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -