我在显示文件当前修改日期时遇到了一些问题。
public class MyAdapter extends ArrayAdapter<String> {
String dir = "/FileDirectory/";
File file = new File(Environment.getExternalStorageDirectory() + dir);
private final Activity context;
Date lastModified = new Date(file.lastModified());
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
String formattedDateString = formatter.format(lastModified);
private String dateFormat = "dd/MM/yyyy HH:mm:ss";
static class ViewHolder {
public TextView text;
}
public MyAdapter(Activity context, String[] date) {
super(context, R.layout.row, date);
this.context = context;
formatter = new SimpleDateFormat(dateFormat);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.row, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) rowView.findViewById(R.id.FilePath);
rowView.setTag(viewHolder);
}
ViewHolder holder = (ViewHolder) rowView.getTag();
String s = formattedDateString;
holder.text.setText(s);
return rowView;
}
}
到目前为止,它只显示所有文件上目录的最后修改日期。任何帮助将不胜感激!