0

I am trying to load the file paths into a string array (path) but I am stuck. Here is my code:

public class MainActivity extends ListActivity{

String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Video/";

String[] videoFileList = {

        path,

};

public class MyThumbnaildapter extends ArrayAdapter<String>{

    public MyThumbnaildapter(Context context, int textViewResourceId,
            String[] objects) {
        super(context, textViewResourceId, objects);
        // TODO Auto-generated constructor stub
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        View row = convertView;
        if(row==null){
            LayoutInflater inflater=getLayoutInflater();
            row=inflater.inflate(R.layout.row, parent, false);
        }

        ImageView imageThumbnail = (ImageView)row.findViewById(R.id.Thumbnail);

        Bitmap bmThumbnail;
        bmThumbnail = ThumbnailUtils.createVideoThumbnail(videoFileList[position], Thumbnails.MINI_KIND);
        imageThumbnail.setImageBitmap(bmThumbnail);

        return row;
    }

}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setListAdapter(new MyThumbnaildapter(MainActivity.this, R.layout.row, videoFileList));
}

}

I am trying to load video paths. I can load one specific file, but not all the files in the directory. Any help would be greatly appreciated. Thanks!

2
  • You should explain what your current results are. Commented Sep 12, 2013 at 23:26
  • If my path is to the direct video file, everything works fine. However the user is going to my putting files into the folder, so there is no way I can know the exact names/how many. I want to put all of the files' paths present in that folder into a string array. Commented Sep 12, 2013 at 23:32

2 Answers 2

3

Have a look at File.list(). Create a File object with the path to the files. list() will return an array of String.

Example as requested.

File pathToFiles = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Video/");

String[] videoFileList = pathToFiles.list();
Sign up to request clarification or add additional context in comments.

1 Comment

Could yo provide an example?
0

To iterate over the files of a given directory, use

new File(path).listFiles()

or some of the new Java 7 APIs, e.g. :

Path dir = new File(path).toPath();     
DirectoryStream<Path> directoryStream = Files.newDirectoryStream(dir);

1 Comment

listFiles() returns an array of File not String.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.