Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3998726
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:33:46+00:00 2026-05-20T07:33:46+00:00

I have a long press option on my listview which will delete the long

  • 0

I have a long press option on my listview which will delete the long pressed db entry. The delete does actually work. If i come out of the app and go back in i am presented with my ‘no rows’ message. Perfect.

In my code I first call the DBadapter method to delete a row. I then call a fetchallnotes method in the dbadapter to refresh my listview. The last row won’t disappear, however, on this fetchallnotes call.. Only on the fetchallnotes call in my onCreate.

Here is my Context Menu call which calls my DBAdapter method

db.deleteNote(info.id);
getSnapz();

This my my deleteNote method in DBAdapter

public boolean deleteNote(long rowId) {
     return db.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
}

here is my getSnapz method, which is in my Main activity which is where my listview is

public void getSnapz(){
    try {
        Cursor c = db.fetchAllNotes();
        //requery cursor incase the last entry has been deleted
        c.requery();
        startManagingCursor(c);
        if(c.moveToFirst()){

        String[] from = new String[]{DBAdapter.KEY_TYPE,DBAdapter.KEY_WEIGHT,DBAdapter.KEY_DATE,DBAdapter.KEY_PLACE};
        int[] to = new int[]{R.id.typecol,R.id.weightcol,R.id.datecol,R.id.placecol};

        SimpleCursorAdapter simple = new SimpleCursorAdapter(this, R.layout.snapz_row, c, from, to);
        setListAdapter(simple);
        }

    } catch (Exception e) {
        Log.e(TAG,e.toString());
    }
}

And here is my fetchAllNotes method in DBAdapter

public Cursor fetchAllNotes() throws Exception{
    Cursor c = db.query(DATABASE_TABLE, new String[] {KEY_ROWID,KEY_URI, KEY_DATE,KEY_TYPE,KEY_WEIGHT,
            KEY_PLACE}, 
            null, null, null, null, null );

    return c;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:33:46+00:00Added an answer on May 20, 2026 at 7:33 am

    After you delete the last row, the cursor returned is empty. Therefore c.moveToFirst() returns false, your whole if block is skipped, and your listview is left unchanged, still showing the just-deleted row.

    It works when you delete one of several rows because moveToFirst() returns success as long as there was another row still left.

    It works when you exit and resume because at that point the activity is recreated and the listview starts uninitialized.

    Solution: drop the if statement completely. SimpleCursorAdapter should be happy with a cursor with 0 rows.

    Long term better yet, migrate to a ContentProvider and use the ContentObserver model to make sure your cursors update themselves when the database they reflect changes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have long recognized that any set of whitespace in an HTML file will
I have the android:cacheColorHint=#00000000 set on my ListView, which fixed this issue in one
I have developed a sound board application, in which I set ringtones on long
I have a ListView with listeners for a long click and a regular click.
Okay so i have a class called viewList. When the item it long pressed
I have long since forgotten the password for the root user on one of
I have long been wondering why lazy evaluation is useful. I have yet to
I have long tables generated by datagrid control that go beyond the page width.
I have long been of the opinion that the time and resources it would
I wish to have long and short forms of command line options invoked using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.