Note that there are some explanatory texts on larger screens.

plurals
  1. PODelete substring with contextmenu in listactivity
    text
    copied!<p>I have a context menu to delete data on listactivity, but when I tried it on my application, the data is not deleted. Previously I enter data using substring query on my AlmagHelper class. if there is something wrong with the coding that I created? please help ..</p> <p>This activity class that I created ..</p> <pre><code>public class Pendapatan extends ListActivity { Cursor model=null; AlmagAdapter adapter=null; AlmagtHelper helper=null; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.listview_nasabah); helper=new AlmagtHelper(this); model=helper.getAllPendapatan(); startManagingCursor(model); adapter=new AlmagAdapter(model); setListAdapter(adapter); registerForContextMenu(getListView()); } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); getMenuInflater().inflate(R.menu.action_pendapatan, menu); } @Override public boolean onContextItemSelected(MenuItem item){ AdapterView.AdapterContextMenuInfo info= (AdapterContextMenuInfo)item.getMenuInfo(); switch (item.getItemId()) { case R.id.hapus_pendapatan: delete(info.id); return(true); } return false; } private void delete(final long rowId) { if (rowId&gt;0) { new AlertDialog.Builder(this) .setTitle("Hapus") .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prosesDelete(rowId); } }) .setNegativeButton("Batal", new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog, int whichButton) { } }).show(); } } private void prosesDelete(long rowId) { String[] args={String.valueOf(rowId)}; //is there something wrong with this code? helper.getWritableDatabase().delete("pendapatan", "_id =?", args); model.requery(); } </code></pre> <p>This is the code to enter data contained in the class AlmagHelper ..</p> <pre><code>public Cursor getAllPendapatan() { return(getReadableDatabase() .rawQuery("SELECT substr(_id, 1, 10) as _id, sum(value) as total FROM pendapatan GROUP BY _id ", null)); } </code></pre> <p>I've tried using this code but it does not work</p> <pre><code>private void prosesDelete(long rowId) { String[] args={String.valueOf(rowId)}; helper.getWritableDatabase().delete("pendapatan", "(substr(_id, 1, 10)) = _id =?", args); model.requery(); } </code></pre> <p>is there any solution for me to do? any solution will be very useful for me. thanks :-)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload