お願い助けて。プロジェクトで actionBarSherlock を使用しています。そして、actionModeにエラーがあります。actionMode (削除と移動) に 2 つの項目があります。アイテム移動を押すとアクションモードを終了できません。
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() にアイテムが選択されていません。DatePickerDialog
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() でアクション モードを終了するにはどうすればよいですか? または他の方法はありますか?