单击此按钮,我们将看到一个对话框,其中包含有关特定文件的以下详细信息:
对话框示例
直到现在,我已经找到了Name,Path,Size属性以及最后修改日期,但我无法理解如何实现date created属性。
private void showDetails(String fileName){
File file = new File(fileName);
String filePath = file.getParent();
double fileSize = file.length();
long creationDate = file.lastModified();
Date dateCreated = new Date(creationDate);
new MaterialDialog.Builder(mContext)
.title(R.string.creating_pdf)
.content("File Name: " + file.getName() +"\nFile Path: " + filePath + "\nFile Size: " + fileSize/(1000*1000) + " Mb\nFile Created On: " + dateCreated)
.show();
}
我的问题:
file.lastModified()
是获取上次修改日期和时间的正确方法吗?答案 0 :(得分:1)
您可以使用此方法
AlertDialog.Builder alertDialog = new AlertDialog.Builder(AlertDialogActivity.this);
// Setting Dialog Title
alertDialog.setTitle(R.string.creating_pdf);
// Setting Dialog Message
alertDialog.setMessage("File Name: " + file.getName() +"\nFile Path: " + filePath + "\nFile Size: " + fileSize/(1000*1000) + " Mb\nFile Created On: " + dateCreated);
alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
}
});
alertDialog.setNegativeButton("Fix Date", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
// Showing Alert Message
alertDialog.show();
或者您可以为对话框视图制作自定义布局
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.dialog);
TextView text = (TextView) dialog.findViewById(R.id.text_dialog);
text.setText(msg);
Button dialogButton = (Button) dialog.findViewById(R.id.btn_dialog);
dialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();