1

请帮帮我。我在我的项目中使用 actionBarSherlock。而且我在actionMode中有错误。我在 actionMode 中有两个项目(删除和移动)。当我按下项目移动时,我无法完成动作模式。

public boolean onActionItemClicked(ActionMode mode,  com.actionbarsherlock.view.MenuItem item) {

        Log.d(Tag, "onActionItemClicked");

        switch (item.getItemId()) {
        case R.id.menu_delete:

            //***********************
            //               int index = MainActivity.pager.getCurrentItem();
            //               adapter = MainActivity.pager.getAdapter();
            //               MyFragment fragment = adapter.getFragment(index);
            //
            //***********************
            // retrieve selected items and delete them out
            Log.d(Tag, "R.id.menu_delete");
            SparseBooleanArray selected = MySqlCursorAdapter.getSelectedIds();
            for (int i = (selected.size() - 1); i >= 0; i--) {
                if (selected.valueAt(i)) {
                    long selectedItem = adapterForDel.getItemId(selected.keyAt(i));
                    DBHelper dbHelper = new DBHelper(getActivity());
                    SQLiteDatabase db = dbHelper.getWritableDatabase();
                    int delCount = db.delete("mytable", "_id = " + String.valueOf(selectedItem), null);
                }
                //   remove(selectedItem);
            }

            try {
                MainActivity.update();
            } catch (Exception e) {
                // TODO: handle exception
            }

            try {
                ListTsk.update();
            } catch (Exception e) {
                // TODO: handle exception

            }
            mode.finish(); // Action picked, so close the CAB
            break;
            //  return true;

        case R.id.menu_move:
            //  Toast.makeText(getActivity(), "Изменение во втором списке", Toast.LENGTH_SHORT).show();
            //***********************************
            dbHelper = new DBHelper(getActivity());
            getActivity().showDialog(MainActivity.TIME_DIALOG_ID);
            sFA = getSherlockActivity();
            Log.d(Tag, "menu_move");

            mode.finish();
            //***********************************
            break;
        default:
            return false;

        }
        return true;
    }

如果我添加 mode.finish() ,那么在 onDateSet() 我没有选择项目。日期选择器对话框

public static DatePickerDialog.OnDateSetListener datePickerListener 
= new DatePickerDialog.OnDateSetListener() {

    // when dialog box is closed, below method will be called.
    public void onDateSet(DatePicker view, int selectedYear,
            int selectedMonth, int selectedDay) {
        mYear = selectedYear;
        mMonth = selectedMonth;
        mDay = selectedDay;
        time_up_var1= new StringBuilder().append(AddLineBD.pad(mYear))
                .append("-").append(AddLineBD.pad(mMonth)).append("-").append(AddLineBD.pad(mDay));
        //  Log.d(Tag, "time_up_var1="+time_up_var1.toString());

        //******************************
        SparseBooleanArray selected_items = MySqlCursorAdapter.getSelectedIds();
        for (int i = (selected_items.size() - 1); i >= 0; i--) {
            if (selected_items.valueAt(i)) {
                long selectedItem = PageFragment.adapterForDel.getItemId(selected_items.keyAt(i));
                //  DBHelper dbHelper = new DBHelper(getActivity());
                SQLiteDatabase db = dbHelper.getWritableDatabase();
                ContentValues cvList = new ContentValues();
                cvList.put("data_id", time_up_var1.toString());
                int updCountList = db.update("mytable", cvList, "_id = ?",
                        new String[] { String.valueOf(selectedItem) });
                //int delCount = db.delete("mytable", "_id = " + String.valueOf(selectedItem), null);
            }
            //   remove(selectedItem);
        }

        MainActivity.update();
    //  ActionMode pActionMode = sFA.

    }
};

如何在 onDateSet() 中完成动作模式?还是有其他方法?

4

0 回答 0