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

  • Home
  • SEARCH
  • 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 8264621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:31:31+00:00 2026-06-08T04:31:31+00:00

I have a table from which i have to get rows which have KEY_DATE

  • 0

I have a table from which i have to get rows which have KEY_DATE = dat.

I am then saving these rows as objects and returning a list of those objects.

The problem is that if I have 4 entries in my table, then instead of getting all 4 rows, I’m getting the last row 4 times.

Here is my code…

while(!l.isEmpty())
    {
        hd = l.get(0);
        l.remove(0);
        map = new HashMap<String, String>();
        Log.w("myapp",hd._name+hd._price+hd._qty);

        map.put("item", hd._name);
        map.put("price", Double.toString(hd._price));
        map.put("qty", Integer.toString(hd._qty));
        map.put("total", Double.toString(hd._price*hd._qty));
        mylist.add(n++,map);
    }

    SimpleAdapter mSchedule = new SimpleAdapter(getActivity(), mylist, R.layout.details_item_list, new String[] {"item", "price", "qty" , "total"}, new int[] {R.id.col1, R.id.col2, R.id.col3, R.id.col4});
    list.setAdapter(mSchedule);

The items are being retrived , but my listview is showing the last item only mutliplied by the number of items in my sql table . Am i using the map.put() and add() function in loop correctly .

  • 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-08T04:31:33+00:00Added an answer on June 8, 2026 at 4:31 am

    That’s because you only have one instance of HistoryDetails, which you add 4 times inside your List, modifying it on each iteration. You need to put hd = new HistoryDetails(); inside your loop, like

    hd = new HistoryDetails();
    
    hd._qty = Integer.parseInt(cursor.getString(3));
    hd._name = c.getString(1);
    hd._price = Double.parseDouble(c.getString(2));
    
    l.add(hd);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to get data from Oracle Table in which I have one datefield
I have this method which will remove all rows from a table but I
We have a large MyISAM table to which rows get inserted to the bottom
I have a table from which I query data to display resultset using stored
I have the typical emp table from which i want to fetch the hierarchical
Let's say I have SELECT name FROM table which gives me something like foo
I have a table which is being dynamically populated from MySQL. The table has
I have a DataGridView which is filling from Table in SQL Server Database. One
I have created programme in which we navigate from table view to a simple
I have a table which looks like this: mysql> SHOW COLUMNS FROM Users; +------------+--------------+------+-----+---------+----------------+

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.