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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:53:08+00:00 2026-06-02T19:53:08+00:00

I am trying to display a sub-total of the database value bound to each

  • 0

I am trying to display a sub-total of the database value bound to each row of my ListView. I don’t want to keep the sub-total as a database column, so I am trying to accumulate the values as they are displayed. Of course this brings up the obvious problems of how to deal with scrolling, which will display and re-display a value, messing up the running sub-total.

To elaborate, each listview row has two fields, a value and a sub-total. The value comes from a database row, the sub-total is the total of all database rows up to and including that row. I don’t want to include the sub-total into the database row if I don’t have to, because that would make inserting and deleting rows more difficult.

Any ideas?

  • 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-02T19:53:10+00:00Added an answer on June 2, 2026 at 7:53 pm

    Create a custom adapter, create an array to hold the subtotal and use that in your getView to maintain your subtotal even when scrolled.

    public class CustomCursorAdapter extends SimpleCursorAdapter {
    
    private Cursor c;
    private Context context;
    private Activity activity;
    private int[] subtotal;
    private int subtotalhold;
    private int layout;
    
    public CustomCursorAdapter(Context context, int layout, Cursor c,
            String[] from, int[] to) {
        super(context, layout, c, from, to);
    
        this.c = c;
        this.context = context;
        this.activity = (Activity) context;
        this.layout = layout;
    
        subtotal = new int[c.getCount()];
        subtotalhold=0;
        c.moveToFirst();
        int i = 0;
        while (c.isAfterLast() == false) {
            subtotalhold = subtotalhold + c.getInt(columnIndex);
            subtotal[i] = subtotalhold;
            i++;
            c.moveToNext();
        }
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null)
            convertView = View.inflate(context, layout, null);
        c.moveToPosition(position);
    
        TextView subtotal = (TextView) convertView.findViewById(R.id.subtotal);
                subtotal.setText(subtotal[position]);
    
                // rest of your code to populate the list row
        return (row);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to display a notification using Easy Notification , but I don't want
I'm trying to get images to display in a WPF ListView styled like a
I am trying to display Total Order Amount Per Day in the Present Month.
I have several products each with several images. I am trying to display 3
Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s
Im trying do display my body onload in a div tag, but cant solve
Im trying to display in my website photos froma photoset I have in Flickr.
Im trying to display some files in a web page so the user can
I'm trying to display an UIPopoverController from the rect of a selected text in
I'm trying to display a forum/category. I need to get the latest posts. The

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.