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 8956511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:48:10+00:00 2026-06-15T14:48:10+00:00

I’m working on an app that allows the user to create notes while rehearsing

  • 0

I’m working on an app that allows the user to create notes while rehearsing a play. The user can view the notes they have created in a listview, and edit and delete them if they wish.

Take for example the user creates 3 notes. In the database, the row_id’s will be 1, 2 and 3. So when the user views the notes in the listview, they will also be in the order 1, 2, 3 (intially 0, 1, 2 before I increment the values). So the user can view and delete the correct row from the database.

The problem arises when the user decides to delete a note. Say the user deletes the note in position 2. Thus our database will have row_id’s 1 and 3. But in the listview, they will be in the position 1 and 2. So if the user clicks on the note in position 2 in the listview it should return the row in the database with row_id 3. However it tries to look for the row_id 2 which doesn’t exist, and hence crashes.

I need to know how to obtain the corresponding row_id, given the user’s selection in the listview. Here is the code below that does this:

// When the user selects "Delete" in context menu
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
            .getMenuInfo();
    switch (item.getItemId()) {
    case DELETE_ID:
        deleteNote(info.id + 1);
        return true;
    }
    return super.onContextItemSelected(item);
}

// This method actually deletes the selected note
private void deleteNote(long id) {
    Log.d(TAG, "Deleting row: " + id);
    mNDbAdapter.deleteNote(id);
    mCursor = mNDbAdapter.fetchAllNotes();
    startManagingCursor(mCursor);
    fillData();
    // TODO: Update play database if there are no notes left for a line.
}

// When the user clicks on an item, display the selected note
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    viewNote(id, "", "", true);

}

// This is where we display the note in a custom alert dialog. I've ommited
// the rest of the code in this method because the problem lies in this line:
// "mCursor = mNDbAdapter.fetchNote(newId);"
// I need to replace "newId" with the row_id in the database.
private void viewNote(long id, String defaultTitle, String defaultNote,
        boolean fresh) {

    final int lineNumber;
    String title;
    String note;

    id++;

    final long newId = id;

    Log.d(TAG, "Returning row: " + newId);

    mCursor = mNDbAdapter.fetchNote(newId);

    lineNumber = (mCursor.getInt(mCursor.getColumnIndex("number")));
    title = (mCursor.getString(mCursor.getColumnIndex("title")));
    note = (mCursor.getString(mCursor.getColumnIndex("note")));

            .
            .
            .
}

Let me know if you would like me to show anymore code. It seems like something so simple but I just can’t find a solution.

Thanks!

EDIT

I fixed the problem. I answered the question below.

  • 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-06-15T14:48:11+00:00Added an answer on June 15, 2026 at 2:48 pm

    Okay I fixed the problem (temporarily at least).

    The problem was I was using my own adapter class I created. It was not keeping track of which item in the list corresponded with the item in the database. I have now rewritten the “fillData()” method using a SimpleCursorAdapter.

    This is the OLD implementation, with my own custom adapter:

    private void fillData() {
        String note;
        notes = new ArrayList<String>();
    
        // Populate arraylist with database data
        if (mCursor.moveToFirst()) {
            do {
                // Get current row's character and line
                note = mCursor.getString(mCursor.getColumnIndex("title"));
                Log.d(TAG, "Adding note: " + note);
                notes.add(note);
            } while (mCursor.moveToNext());
        }
    
        // Fill list with our custom adapter
        NoteAdapter adapter = new NoteAdapter(this, R.layout.note_row_layout,
                notes);
        setListAdapter(adapter);
    }
    

    and this is the same class rewitten with a SimpleCursorAdapter:

    private void fillData() {
        mFrom = new String[] { NoteDbAdapter.KEY_TITLE };
        mTo = new int[] { R.id.textNote };
    
        // Now create an array adapter and set it to display using our row
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
                R.layout.note_row_layout, mCursor, mFrom, mTo);
    
        setListAdapter(adapter);
    }
    

    The reason I created my own adapter class was because I also had a checkbox in each row of the list (for multi-delete).

    My question now is, am I able to obtain the state of each checkbox (whether its checked or not) when the user decides to do a multiple delete when using a SimpleCursorAdapter?

    Thanks.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm trying to create an if statement in PHP that prevents a single post
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.