【发布时间】:2015-06-01 07:38:02
【问题描述】:
private List<String> mitem = null;
private List<String> mpath = null;
String dirPath = Environment.getExternalStorageDirectory().getPath();
private void getDir() {
mitem = new ArrayList<String>();
mpath = new ArrayList<String>();
File f = new File(dirPath);
File[] files = f.listFiles();
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (!file.isHidden() && file.canRead()) {
mpath.add(file.getPath());
if (file.isDirectory()) {
// Folder names
mitem.add(file.getName() + "/");
} else {
// File name
mitem.add(file.getName());
}
}
}
fileList = new FileManagerAdapter(this, mitem, mpath);
listview.setAdapter(fileList);
listview.setOnItemClickListener(onitemclick);
}
这里我将文件和文件夹列表添加到 ArrayList 的某个路径上,如何首先对所有文件夹进行排序,最后对所有文件进行排序。我应该使用什么样的排序技术来实现这一点。提前致谢。
更新:CustomAdapter
public class FileManagerAdapter extends ArrayAdapter<String> {
private List<String> mitem;
private Context mContext;
public FileManagerAdapter(Context context, List<String> item,
List<String> path) {
super(context, R.layout.fileadapter_list, item);
this.mContext = context;
this.mitem = item;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.fileadapter_list, null);
}
TextView txtTitle = (TextView) convertView.findViewById(R.id.txt);
txtTitle.setText(mitem.get(position));
return convertView;
}
}
【问题讨论】:
-
您目前使用的任何挑战方法是否面临?
-
是的,文件和文件夹都是混合的。我希望它以一种排序的方式。 @kishorJoshi
标签: android arraylist android-arrayadapter