I need to get all the videos from "/ SDCard / Folder / SubFolder" and display them in the GridView. I can save the video to the desired subfolder that I created, and I can see them directly from the folder. But I want to show them in a GridView, but when I run my code, it only displays a black screen. Here is my code, please tell me what mistake I am making here.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gridview_main);
if (!Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
Toast.makeText(this, "Error! No SDCARD Found!", Toast.LENGTH_LONG)
.show();
} else {
file = new File(Environment.getExternalStorageDirectory()
+ File.separator + "/SDCard/Picture/MyCameraVideo");
file.mkdirs();
}
if (file.isDirectory()) {
listFile = file.listFiles();
FilePathStrings = new String[listFile.length];
FileNameStrings = new String[listFile.length];
for (int i = 0; i < listFile.length; i++) {
FilePathStrings[i] = listFile[i].getAbsolutePath();
FileNameStrings[i] = listFile[i].getName();
}
}
grid = (GridView) findViewById(R.id.gridview);
adapter = new GridViewAdapter(this, FilePathStrings, FileNameStrings);
grid.setAdapter(adapter);
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);
}
});
}
}
source
share