如何从** SDCard /文件夹/子文件夹中获取GridView中的视频“

时间:2014-09-30 10:45:48

标签: android gridview video android-sdcard

我必须从“/ SDCard / Folder / SubFolder”中获取所有视频,然后在GridView中显示它们。 我可以将视频保存到我创建的所需子文件夹中,并可以直接从文件夹中查看。但是我想将它们显示到GridView中,但是当我运行我的代码时,它只显示黑色的空白屏幕。这是我的代码,请告诉我我在这里做的错误..

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gridview_main);


        // Check for SD Card
        if (!Environment.getExternalStorageState().equals(
                Environment.MEDIA_MOUNTED)) {
            Toast.makeText(this, "Error! No SDCARD Found!", Toast.LENGTH_LONG)
                    .show();
        } else {
            // Locate the image folder in your SD Card
            file = new File(Environment.getExternalStorageDirectory()
                    + File.separator + "/SDCard/Picture/MyCameraVideo");
            // Create a new folder if no folder named SDImageTutorial exist
            file.mkdirs();
        }

        if (file.isDirectory()) {
            listFile = file.listFiles();
            // Create a String array for FilePathStrings
            FilePathStrings = new String[listFile.length];
            // Create a String array for FileNameStrings
            FileNameStrings = new String[listFile.length];

            for (int i = 0; i < listFile.length; i++) {
                // Get the path of the image file
                FilePathStrings[i] = listFile[i].getAbsolutePath();
                // Get the name image file
                FileNameStrings[i] = listFile[i].getName();
            }
        }

        // Locate the GridView in gridview_main.xml
        grid = (GridView) findViewById(R.id.gridview);
        // Pass String arrays to LazyAdapter Class
        adapter = new GridViewAdapter(this, FilePathStrings, FileNameStrings);
        // Set the LazyAdapter to the GridView
        grid.setAdapter(adapter);

        // Capture gridview item click
        grid.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {

                Intent i = new Intent(ViewActivity.this, ViewImage.class);
                i.putExtra("filepath", FilePathStrings);
                i.putExtra("filename", FileNameStrings);
                i.putExtra("position", position);
                startActivity(i);
            }

        });
    }

}

0 个答案:

没有答案