Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to list all files and folders locating on sd card
    text
    copied!<p>I have made a program that list all files and folders(f&amp;f) locating on sd card. If i touch one of the list item ( if it is a folder ) then the list shows faf locating on that folder. </p> <p>Here is the source code</p> <pre><code>public class FileList extends ListActivity { private File file; private List&lt;String&gt; myList; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myList = new ArrayList&lt;String&gt;(); String root_sd = Environment.getExternalStorageDirectory().toString(); file = new File( root_sd + "/external_sd" ) ; File list[] = file.listFiles(); for( int i=0; i&lt; list.length; i++) { myList.add( list[i].getName() ); } setListAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, myList )); } protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); File temp_file = new File( file, myList.get( position ) ); if( !temp_file.isFile()) { file = new File( file, myList.get( position )); File list[] = file.listFiles(); myList.clear(); for( int i=0; i&lt; list.length; i++) { myList.add( list[i].getName() ); } Toast.makeText(getApplicationContext(), file.toString(), Toast.LENGTH_LONG).show(); setListAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, myList )); } } @Override public boolean dispatchKeyEvent(KeyEvent event) { if( KeyEvent.KEYCODE_BACK == event.getKeyCode()) { String parent = file.getParent().toString(); file = new File( parent ) ; File list[] = file.listFiles(); myList.clear(); for( int i=0; i&lt; list.length; i++) { myList.add( list[i].getName() ); } Toast.makeText(getApplicationContext(), parent, Toast.LENGTH_LONG).show(); setListAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, myList )); } return true; } } </code></pre> <p>Now i have two questions</p> <ol> <li><p>when i touch "back" button then it list back two step. say currently the list is showing the f&amp;f under "external_sd/Video/Bangla" . After pressing back button the list is not showing f&amp;f under "external_sd/Video/", but under "external_sd/".</p></li> <li><p>Is there a better solution to show all f&amp;f like JFileChooser in java ?</p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload