@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
try{
switch(item.getItemId()) {
case INSERT_ID:
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.alert_dialog_category, null);
final EditText mCategory=(EditText) textEntryView.findViewById(R.id.category_edit);
new AlertDialog.Builder(this)
.setView(textEntryView)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String category=mCategory.getText().toString();
if (category.length()>5){
category=category.substring(0, 5);
}
mDbHelper.createCategory(category);
mList.setAdapter(getAdapter());
TabBookKeeping.fillAdapter();
final Calendar c = Calendar.getInstance();
TabBookKeeping.aggiornaMap(c.get(Calendar.YEAR));
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked cancel so do some stuff */
}
})
.show();
break;
case DELETE_ID:
String category=mList.getSelectedItem().toString();
mDbHelper.deleteCategory(category);
mList.setAdapter(getAdapter());
TabBookKeeping.fillAdapter();
final Calendar c = Calendar.getInstance();
TabBookKeeping.aggiornaMap(c.get(Calendar.YEAR));
break;
}
} catch (Exception ex){
Log.v("OnMenuItemSelected:",ex.toString());
}
return super.onMenuItemSelected(featureId, item);
}