我有以下方法:
public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState ) {
final RelativeLayout mFrame3 = (RelativeLayout) inflater.inflate( R.layout.ptrip, container, false );
File folder = new File(Environment.getExternalStorageDirectory() + "/tc/");
ListView lv;
ArrayList<String> FilesInFolder = GetFiles(folder.getAbsolutePath());
Toast.makeText(getActivity(), FilesInFolder.get(0).toString(), 2000).show(); //display filename (0)
////////////////////////
///////////////////////
//would this work:
//for (int i = 0; i <= FilesInFolder.length(); i++) {
//long lastTime = FilesInFolder[0].lastModified();
//String dateString = DateFormat.format("MM/dd/yyyy", new Date(lastTime)).toString(); //last modified date?
//String sizeString = getReadableSize(FolderInFiles[i].length()); //file size?
//}
//////////////////////
//////////////////////
lv = (ListView) mFrame3.findViewById(R.id.lvFiles);
lv.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, FilesInFolder));
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// Clicking on items
//Toast.makeText(getActivity(), "Item " + (position + 1) + ": ID" + v, Toast.LENGTH_SHORT).show();
}
});
return mFrame3;
}
我的 GetFolder 函数是:
public ArrayList<String> GetFiles(String DirectoryPath) {
ArrayList<String> MyFiles = new ArrayList<String>();
File f = new File(DirectoryPath);
//f.mkdirs();
File[] files = f.listFiles();
if (files.length == 0)
return null;
else {
for (int i=0; i<files.length; i++) {
if (files[i].getName().endsWith(".tol")) {
long lastTime = files[i].lastModified();
String dateString = DateFormat.format("MM/dd/yyyy", new Date(lastTime)).toString();
String sizeString = getReadableSize(files[i].length());
//String fileName = files[i].getName().substring(0, files[i].getName().lastIndexOf("."));
MyFiles.add(files[i].getName());
//MyFiles.add("Trip Name: " + fileName + "\nTrip Taken On: " + dateString + "\n" + sizeString);
}
}
}
return MyFiles;
}
我如何得到fileSize
andlastModifiedDate
里面的onCreateMethod
?我注释掉了方法内部的fileSize
and ,因为我试图只获取文件名,这样我就可以读取方法内部的文件以在 MultiLine EditText 中显示它的 ASCII 内容。lastModifiedDate
GetFolder
onCreate
这会像上面添加的那样工作吗onCreate
:
//display filename (0)
////////////////////////
///////////////////////
//would this work:
//for (int i = 0; i <= FilesInFolder.length(); i++) {
//long lastTime = FilesInFolder[0].lastModified();
//String dateString = DateFormat.format("MM/dd/yyyy", new Date(lastTime)).toString(); //last modified date?
//String sizeString = getReadableSize(FolderInFiles[i].length()); //file size?
//}
//////////////////////
//////////////////////