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,如何首先排序所有文件夾,最後排序所有文件。我應該使用什麼樣的排序技術來實現這一點。提前致謝。ArrayList排序Android
更新: 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;
}
}
您面臨迄今爲止使用的任何挑戰方法嗎? – rogerwar
是的,這兩個文件和文件夾是混合的。我希望它能夠以一種排序的方式。 @kishorJoshi –
按照此鏈接http://stackoverflow.com/questions/8243450/sorting-of-files-according-to-file-or-folder – rogerwar