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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:31:48+00:00 2026-06-03T08:31:48+00:00

SOLVED BELOW See below for solution I have a ListView with a custom adapter

  • 0

SOLVED BELOW

See below for solution


I have a ListView with a custom adapter which extends CursorAdapter. When the user clicks on an item in the ListView I want to open a new Activity(launched from the openDigitalBusinessCardActivity method), with the new Activity based upon the particular item in the ListView that was clicked. The new Activity needs the field merchantID from the database so I need to access this and then pass to the new Activity in my Intent.

However, I cannot get working how to access the correct data in my database based upon the feedback of the ListView click listener.

Eclipse gives me Bad request for field slot errors. My code for my listener is below:

    list.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {
          // When clicked, show a toast with the TextView text
          Toast.makeText(getApplicationContext(), "Click registered!",
              Toast.LENGTH_SHORT).show();

          db = myDbHelper.getReadableDatabase();

          //Cursor cur = (Cursor) adapter.getCursor();            
          //cur.moveToPosition(position);
          Cursor cur = (Cursor) parent.getItemAtPosition(position);
          //Cursor cur = (Cursor)((MyCustomCursorAdapter) list.getAdapter().getItem(position));
          int merchantID = cur.getInt(cur.getColumnIndex("merchantID")); //Get the merchantID

          db.close();

         openDigitalBusinessCardActivity(merchantID);             
        }
      });

My database creation code is this:

private static final String DATABASE_CREATE = 
                "create table " + TABLE_SCORECARD + "(" 
                + COLUMN_MERCHANTID + " integer primary key, " 
                + COLUMN_MERCHANTNAME + " text not null, "
                + COLUMN_MERCHANTTAGLINE + " text not null, "
                + COLUMN_CURRENTSCORE + " Integer, "
                + COLUMN_FREEBIEPOINT + " Integer, "
                + COLUMN_CAMPAIGNID + " Integer, "
                + COLUMN_LISTPOSITION + " Integer);";

—UPDATE—

I have added an _id column to my table and now it looks like my query by the _id from onItemClick is not returning anything as my test on cur.moveToFirst() returns false. So onItemClick is not returning a valid table row number.

list = getListView();

   list.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {
          // When clicked, show a toast with the TextView text
          Toast.makeText(getApplicationContext(), "Click registered!",
              Toast.LENGTH_SHORT).show();

          db = myDbHelper.getReadableDatabase();

          //Cursor cur = (Cursor) adapter.getCursor();            
          //cur.moveToPosition((int) id);
          //Cursor cur = (Cursor) parent.getItemAtPosition((int) id);
          //Cursor cur = (Cursor)((MyCustomCursorAdapter) list.getAdapter().getItem(position));
          Cursor cur = db.rawQuery("select merchantID from scoreCard where _id = "+id,null);
          if(cur.moveToFirst()) {
              //int merchantID = cur.getInt(cur.getColumnIndex("merchantID")); //Get the merchantID
              Toast.makeText(getApplicationContext(), "cur.moveToFirst returned true",
                      Toast.LENGTH_SHORT).show();
          }           

          cur.close();
          db.close();

         // openDigitalBusinessCardActivity(merchantID);              
        }
      });
  • 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-03T08:31:50+00:00Added an answer on June 3, 2026 at 8:31 am

    In the case of Cursor based adapters you get the id of the row in the onItemClick callback, is the id parameter. You should use that.

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

Sidebar

Related Questions

SOLVED: See my solution below! using aspx with C# code behind. I have the
Problem solved, see below Question I'm working in Flex Builder 3 and I have
SOLVED: SEE CORRECTED SOLUTION Area (below) --------------------------------- ORIGINAL TEXT --------------------------- I've created a JavaScript
[SOLVED: See solution below.] I'm having a problem writing a RewriteMap program (using Python).
I have custom view in my application which can be scrolled by the user.
EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
(Problem solved now, see answers below) Hello, in my app I am trying to
[EDIT: Problem solved. Please see my answer below.] In my app I call the
SOLVED I used the solution proposed by Roman below, based on adding an additional
Update: Solved. See fix at bottom. In my iPad app which supports all orientations,

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.