I have a database and need to change to remove and add values and created such a ContextMenu that I have the chance to change and remove the clicked item. But I need for it to know the id of the list item and within the contextMenu so have the ids of the menu. I'm doing the right thing or is there some easier way.
public boolean onContextItemSelected(MenuItem item) {
//Iniciação da Base de dados
final HelperDB MyHelper = new HelperDB(this.getActivity());
SQLiteDatabase db = MyHelper.getWritableDatabase();
String[] projection = {Contrato_DB.CidadeEntry._ID, COLUMN_NOME,
};
// How you want the results sorted in the resulting Cursor
String sortOrder = COLUMN_NOME + " ASC ";
String[] columns = new String[] { "_id", "nome" };
final Cursor c = db.rawQuery("SELECT * FROM cidade ", null);
c.moveToFirst();
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.update: // <-- your custom menu item id here
int id = item.getItemId();
final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
final EditText input = new EditText(getActivity());
Toast.makeText(this.getActivity(),c.getString(tmp),Toast.LENGTH_LONG).show();
alert.setTitle("Editar :" + c.getString(tmp));
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString().trim();
Aucun commentaire:
Enregistrer un commentaire