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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:48:00+00:00 2026-06-01T21:48:00+00:00

I’ve got the following cursor set up to fill a dialog box with a

  • 0

I’ve got the following cursor set up to fill a dialog box with a users payment history

Cursor PaymentsCursor = db.getReadableDatabase().rawQuery(
                "SELECT _id, Date, Payment FROM tblPaymentHistory WHERE DebtName = '"
                        + debtname + "'" + "ORDER BY _id ASC", null);
        SimpleCursorAdapter HistoryAdapter = new SimpleCursorAdapter(this,
                R.layout.paymenthistoryrow, PaymentsCursor, from, to);

The problem is though that if there is more than one type of debt, and payments are made to each debt out of order, when the payment history returns it’s results, it returns as out-of-order row numbers, for example 1,2,6,7,9,12,etc. I know it’s pulling the _id (unique key) from the database, but is there a way to re-base or change the row number in the query, so that each result returns as "1,2,3,4,5,etc" regardless of original ID?

I thought that the ORDER BY _id or even ORDER BY Date ASC would fix this but it didn’t.

My rows in the database look something like this:

1, TEST, 4/13/2012, 250
2, TEST, 4/13/2012, 300
3, TEST, 4/14/2012, 222
4, TEST2, 4/14/2012, 500
5, TEST, 4/15/2012, 600

When the user clicks history for "TEST", it returns back as 1,2,3,5… and if they pull up history for "TEST2", it shows as "4", I’m trying to get it so TEST shows "1,2,3,4" and TEST2 shows "1"

Damn I can’t answer my own answer, but here’s what I ended up doing:

Thanks guys. I found an alternate option that modified the view, so as not having to touch the SqLite db. heres the link that i foundModifying SimpleCursorAdapter's data

And here is the result:

PaymentsCursor = db.getReadableDatabase().rawQuery(
            " SELECT _id, Date, Payment FROM tblPaymentHistory WHERE DebtName = '"
                    + debtname + "'" + "ORDER BY _id ASC", null);

    String[] from = new String[] { DbAdapter.KEY_HISTORY_ID,
            DbAdapter.HISTORY_DATE, DbAdapter.HISTORY_PAYMENT };

    int[] to = new int[] { R.id.PAYMENTNO, R.id.PAYMENTDATE,
            R.id.PAYMENTAMOUNT };

    SimpleCursorAdapter HistoryAdapter = new SimpleCursorAdapter(this,
            R.layout.paymenthistoryrow, PaymentsCursor, from, to);

    HistoryAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int column) {
            if (column == 0) { // let's suppose that the column 0 is the
                                // date

                TextView tv = (TextView) view;
                String rownum = String.valueOf(cursor.getPosition() + 1);
                // here you use SimpleDateFormat to bla blah blah
                tv.setText(rownum);

                return true;
            }
            return false;
        }
    });

    paymenthistory.setAdapter(HistoryAdapter);

It may not be the most glamourous way, but now each time the window comes up with the history, it’s using the row number (plus one) to indicate which # it is.
Thanks all!

  • 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-01T21:48:01+00:00Added an answer on June 1, 2026 at 9:48 pm

    Here is one way to get the “re-based” ids. In this example, the “new ids” are based on the grade (i.e. the “old ids” in your case):

    .headers on
    
    create table foo (name text, grade int);
    
    insert into foo values ('Joe', 45);
    insert into foo values ('Anna', 98);
    insert into foo values ('Julie', 78);
    
    select name, 
           grade, 
           (select count(*) from foo t1 where t1.grade>=t2.grade) as rank  
    from foo t2;
    
    select name, 
           grade, 
           (select count(*) from foo t1 where t1.grade>=t2.grade) as rank  
    from foo t2
    order by rank;
    

    Having saved this as foo.sql, I get this:

    [someone@somewhere tmp]$ sqlite3 < foo.sql 
    name|grade|rank
    Joe|45|3
    Anna|98|1
    Julie|78|2
    name|grade|rank
    Anna|98|1
    Julie|78|2
    Joe|45|3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.