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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:03:31+00:00 2026-06-04T23:03:31+00:00

I can populate my ListView of items from my SQLiteDatabase in lunch.java . now

  • 0

I can populate my ListView of items from my SQLiteDatabase in lunch.java. now I want to click the one item(total 8 items inside the ListView) and go to a new activity called Display.java and display all the nutrition facts of it.

AFTER EDITING

lunch.java:

public void onItemClick(AdapterView<?> parent, View v, int pos, long id) {
    switch(pos)

    {
    case 0 :
        String mealName = (String) parent.getItemAtPosition(pos);
        Cursor cursor = dbopener.getBreakfastDetails(mealName);
        cursor.moveToNext();
        id = cursor.getLong(cursor.getColumnIndex(mealName));
        String message = cursor.getString(1)  + "\n" + cursor.getInt(2);
        Intent event1 = new Intent("com.edu.tp.iit.mns.Display");
        event1.putExtra("name", id);
        startActivity(event1);
        break;

Display.java

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.display);

        TextView tv = (TextView) findViewById(R.id.tvfoodName);     


        Intent intent = getIntent();
        long id = intent.getLongExtra("name", -1);
        if(id == -1){
            return;
        }

        tv.setText(-1); 

}
  • 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-04T23:03:33+00:00Added an answer on June 4, 2026 at 11:03 pm

    In the onItemcClick you already have the id of the element that was clicked, the id parameter. Use that to identify the item in your next activity:

    public void onItemClick(AdapterView<?> parent, View v, int pos, long id) {    
        Intent newActivity = new Intent("com.edu.tp.iit.mns.Display");
        newActivity.putExtra("the_key", id);
        startActivity(newActivity);
    }
    

    Then in your Display activity get that long value and get the data from the database corresponding to that id:

    Intent newActivity = getIntent();
    long id = newActivity.getLongExtras("the_key", -1);
    if (id == -1) {
        //something has gone wrong or the activity is not started by the launch activity
        return
    }
    //then query the database and get the data corresponding to the item with the id above
    

    The above code would work for the case of a Cursor based adapter. But you probably use a list based adapter(because of the getItemAtPosition(pos) returning a String and not a Cursor). In this case I would make the getLunchDetails method to return the unique id of that meal name and pass that to the Details activity:

    public void onItemClick(AdapterView<?> parent, View v, int pos, long id) {
        String mealName = (String)parent.getItemAtPosition(pos);
        Cursor cursor = dbopener.getLunchDetails(mealName);
        cursor.moveToNext();
        long id = cursor.getLong(cursor.getColumnIndex("the name of the id column(probably _id"));
        Intent newActivity = new Intent("com.edu.tp.iit.mns.Display");
        newActivity.putExtra("the_key", id);
        startActivity(newActivity);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to populate ListView Item with an object from MyClass. One of
I am using a ListView in which only one item can be checked at
I'd like to populate a listview from 2 tables. Anyone know how I can
How can I do this in Javascript/jQuery from PHP? I am trying to populate
I need to populate ListView with List of objects returned from my Dao object.
I'm trying to populate images from a directory into a listview with a small
I'm trying to populate a listview with products. I can do it, but I
1) I am using a ListView to populate some 2 labels from database. The
When this ListView has more items then can be shown on the screen (you
How can I populate multiple datagrids in flex with a single datasource that is

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.