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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:24:18+00:00 2026-05-26T17:24:18+00:00

What a question! To describe it more clearly: I’m using fragments and my target

  • 0

What a question!
To describe it more clearly:
I’m using fragments and my target is to have a TextView that shows the total sum of a database table column. This total sum should be updated everytime the table is updated in different ways (delete, insert, update).
Without the contentprovider I would write a method in my DBHelper class that would return the value. But the the problem begins.It’s really difficult (till impossible) in fragments to update the textview programmatically. Therefore I like to use the contentprovider because it always informs my listviews about changes without any additional work from my side. In this case (contentprovider) I have (imho) to use the loader methods onCreateLoader() and onLoadFinished() with a cursorloader and a uri. But they all are returning a cursor object and that’s nothing I can attach on this single textview.
After all the days working on listviews and contentproviders my thinking is maybe too “bigpictured” so that I’m not able to see a simple solution for a simple textview. If there is any…

  • 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-05-26T17:24:19+00:00Added an answer on May 26, 2026 at 5:24 pm

    I found one, at least, workaround. Would appreciate if somebody knows a better solution.

    In order to use Loader you have to override 3 methods:

    • onCreateLoader(int id, Bundle arg1)
    • onLoadFinished(Loader loader, Cursor cursor) and
    • onLoaderReset(Loader arg0)

    So let’s say we have a single TextView tv that should be updated via ContentProvider.

    in onCreateLoader():

    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle arg1) {
            String select = "where _id="+id; //id is definied earlier in this program
            loader = new CursorLoader(getActivity(),
                    MaterialContentProvider.READ_SINGLE_MATSTAMM_URI, null, select, null, null);
        }
        return loader;
    }
    

    MaterialContentProvider.READ_SINGLE_MATSTAMM_URI is my URI that shows the ContentProvider wich db table to use and how. In this case I’ll get a single result.
    This we will get asynchroniosly via onLoadFinished() and here comes my workaround:

    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    
         final TextView tv = (TextView) View.findViewById(R.id.mytextview);
         tv.setText(cursor.getString(cursor.getColumnIndex("myColumn")));
    }
    

    From now on your TextView tv will be updated everytime the content changes in the table that is targeted by the uri in onCreateLoader(). The “trick” is to not give away the cursor like you usually do (with something like “adapter.swap(cursor)”) because there is nothing with an adapter outthere. In order to get a total sum of a column you have to get all the rows of this special column with the cursor (wich means that you have a different uri).

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

Sidebar

Related Questions

Updated I have updated this question to more accurately describe the cause of my
This question is hard to describe succinctly, so bear with me. Currently I have
Thanks for viewing my question. Let me describe the app first. I have a
That's it. My question is aboe in the title. I'll try to describe the
Let me describe my question - I have a Java application - Hibernate as
Simple question that used to puzzle me about Rails: Is it possible to describe
I have 3 MySQL tables that describe a game: gamelist {gameId, ... with Primary(gameId)
We have a terminal emulator (its more then just this, but for the question
I have an array of view controllers (there are more that I have shown):
Not all that sure how I would describe this question, so I'll jump right

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.