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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:28:58+00:00 2026-06-02T07:28:58+00:00

I created a ListView with a CursorAdapter , populated by a table of my

  • 0

I created a ListView with a CursorAdapter, populated by a table of my db. After I added a ContextMenu that with a long click on the desired line of ListView pick info from my table.

The problem is that: I can not collect the information of that single line of ListView, each line gives me the same result. I think I do something wrong in query.

onCreate:

private void createTabRegistry(SQLiteDatabase db)
    {
        String sql = "CREATE TABLE {0} ({1} INTEGER PRIMARY KEY AUTOINCREMENT, {2} TEXT,{3} INTEGER,{4} TEXT,{5} TEXT,{6} TEXT, {7} TEXT);";
            db.execSQL(MessageFormat.format(sql, TabRegistry.TABLE_NAME, TabRegistry._ID,TabRegistry.TYPE, TabRegistry.DATE, TabRegistry.STATUS, TabRegistry.NUMBER, TabRegistry.MESSAGE, TabRegistry.OTHER));
    }

My query in db class:

public Cursor getRegistry2(long id) {
        return (getReadableDatabase().query(
            TabRegistry.TABLE_NAME, 
            TabRegistry.COLUMNS,
            TabRegistry._ID + " = " + id,
            null,
            null,
            null, 
            null, 
            null));
    }

id of ContextMenu in my activity:

 AdapterView.AdapterContextMenuInfo info= (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
 id = getListAdapter().getItemId(info.position);

My cursor in the activity class:

Cursor c3 = databaseHelper.getRegistry2(id);
if (c3 != null) {
        c3.moveToFirst();
    }                     

dbnumber = (c3.getString(c3.getColumnIndex(TabRegistry.NUMBER))); 

How do I assign to dbnumber string the value of the line of ListView that wonder?

EDIT code that works, but reset the view of listview….

Cursor c3 = (Cursor) getListAdapter().getItem(info.position);
                        startManagingCursor(c3);
                          aaaaa = c3.getString(c3.getColumnIndex(TabRegistry.NUMBER));
                         c3.close();
  • 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-02T07:28:59+00:00Added an answer on June 2, 2026 at 7:28 am

    AdapterView.AdapterContextMenuInfo has a field called id that represents the row id from the database of that selected row. You’ll want to query for that id and not the position field that represents the position in the list:

    rowId = info.id;
    

    and then query your database for the rowId to get that item’s data.

    Edit:

    You’ll probably don’t want to use the solution you added. You close the cursor so no more data(that is why you have to restart the activity, as you probably query the database only in the onCreate method).

    I told you the check if info.id returns different values when you use long press(to show the ContextMenu) different rows in the list, that means that the ContextMenu(probably) selects different row ids for different rows).

    I don’t know what causes your issue(if the delete works I would say there is something in the activity), so I made a small example of what you are trying to do so you can see this type of code:

    http://pastebin.com/Yri03S0T

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

Sidebar

Related Questions

I've created a listview that's filled up with a list of guitars from the
All, The problem I am having is that I created a ListView and set
I created custom adapter for listview which contain text and images, on click of
I have a listview with several items that are created dynamically, each has two
I'm trying to register a long click on my listView row so it will
I created a listview with diff. activity to each items. When the user click
I use following GUI setup: ListView activity CursorAdapter that feeds this list Layout for
I'm trying to populate a dynamically created ListView with an ArrayList that is fetched
I've created a ListView with a GridView component in it. Now trying to fill
HI Guyz i have created a sectioned custom listview using baseadapter its working fine

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.