private void editProject(final Project project, final int position) { final AlertDialog.Builder alert = new AlertDialog.Builder(this); final EditText input = new EditText(this); input.setText(project.getName()); alert.setView(input); alert.setPositiveButton( "Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString().trim(); if (value.length() > 0) { dbhelper.open(); if (dbhelper.updateProject(value, project.getCount(), project.getRowId())) { Toast.makeText( ManageProjectsActivity.this, R.string.renamed_completed, Toast.LENGTH_SHORT) .show(); } else { Toast.makeText( ManageProjectsActivity.this, R.string.failed_rename_project, Toast.LENGTH_SHORT) .show(); } Project tmp = new Project(); tmp.setName(value); tmp.setRowId(project.getRowId()); tmp.setCount(project.getCount()); mList.set(position, tmp); mAdapter.notifyDataSetChanged(); dbhelper.close(); } else { Toast.makeText(ManageProjectsActivity.this, R.string.rename_value, Toast.LENGTH_SHORT) .show(); } } }); alert.setNegativeButton( "Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); alert.setTitle(R.string.rename); alert.show(); }
private void getProjects() { projects = new ArrayList<String>(); mProjects = new ArrayList<Project>(); dbhelper.open(); Cursor c = dbhelper.getAllProjects(); if (c.moveToFirst()) { do { Project tmp = new Project(); tmp.setCount(c.getInt(c.getColumnIndex(DbAdapter.KEY_COUNTER))); tmp.setRowId(c.getLong(c.getColumnIndex(DbAdapter.ROW_ID))); tmp.setName(c.getString(c.getColumnIndex(DbAdapter.KEY_PROJECTNAME))); mProjects.add(tmp); projects.add(tmp.getName()); } while (c.moveToNext()); } c.close(); dbhelper.close(); }