按升序降序排列我的文件夹

时间:2016-05-30 14:10:31

标签: java android

我有一个代码可以在我的应用程序中创建一个文件夹系统,并且我正在尝试安排文件夹以使最新版本保持在最顶层,但是现在最新的文件夹仍然存在。例如,第1个应该是第4个,而第4个应该是第1个(它应该是第1个,第2个,第3个和第4个),但是当我创建它时,它显示为(第4个,第3个,第2个和第1个)。

  public void createNewFolder() {
    View promptsView = inflater.inflate(R.layout.dialog_add_folder, null);
    final Dialog alertDialogBuilder = new Dialog(mContext);
    alertDialogBuilder.setContentView(promptsView);

    alertDialogBuilder.setTitle("Create new Notebook.");

    final EditText editTextName = (EditText) promptsView.findViewById(R.id.editTextName);
    final Button buttonOk = (Button) promptsView.findViewById(R.id.buttonOk);
    final Button buttonCancel = (Button) promptsView.findViewById(R.id.buttonCancel);
    final View colorView = promptsView.findViewById(R.id.colorView);
    final GridView gridView = (GridView) promptsView.findViewById(R.id.gridView);
    gridView.setVisibility(View.VISIBLE);
    final List<String> colors = getColorList();
    gridView.setAdapter(new ColorAdapter(colors));
    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            colorView.setTag(colors.get(i));
            colorView.setBackgroundColor(Color.parseColor(colors.get(i)));
        }
    });
    View.OnClickListener click = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (view == buttonOk) {
                String folderName = editTextName.getText().toString().trim();
                if (folderName.equalsIgnoreCase("")) {
                    Toast.makeText(mContext, "Please enter name.", Toast.LENGTH_LONG).show();
                    return;
                }
                if (colorView.getTag() == null) {
                    Toast.makeText(mContext, "Please select note color.", Toast.LENGTH_LONG).show();
                    return;
                }
                if (db.folderExistInGroup(currentGroupId, folderName)) {
                    Toast.makeText(mContext, "Folder name already exist.", Toast.LENGTH_LONG).show();
                    return;
                }
                db.createGroup(currentGroupId, folderName, colorView.getTag().toString());
                openCurrentGroup();
                try {
                    InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    mgr.hideSoftInputFromWindow(editTextName.getWindowToken(), 0);
                } catch (Exception ex) {

                }
                alertDialogBuilder.dismiss();
            } else if (view == buttonCancel) {
                try {
                    InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    mgr.hideSoftInputFromWindow(editTextName.getWindowToken(), 0);
                } catch (Exception ex) {

                }
                alertDialogBuilder.dismiss();
            }
        }
    };
    buttonOk.setOnClickListener(click);
    buttonCancel.setOnClickListener(click);
    alertDialogBuilder.show();
    }

0 个答案:

没有答案