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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:24:44+00:00 2026-05-19T03:24:44+00:00

I have created a function that updates some values from a database that I

  • 0

I have created a function that updates some values from a database that I need to use on multiple views. Right now each class has its own copy of the code. Basically I read the values and then want to update the text views.

I made a class for the DisplayTop which does the work, and locally its great. But somehow I need to get the (TextView)findViewById sent over the the function I think. I hope I am saying this right. So what is the call to this and how to I resolved the (TextView)findViewById. thanks for any help!

 public void DisplayTop2()
 {


  int UserID = 1;
  String D=Fun.getCurrentDateString();
  String Sql;

  Double a = 0.0;
  Double b = 0.0;

  SQLiteDatabase Db;

  String myPath = DB_PATH + DB_NAME;
  Db = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);



  Sql =" SELECT a,b " +
  " FROM test " +
  " where Dte = '" + D + "' and UserID = " + UserID;

  try {
   Cursor c = Db.rawQuery(Sql, null);

   if (c != null ) {
    if  (c.moveToFirst()) {
     do {


      a +=  (c.getDouble(c.getColumnIndex("a")));

      b +=  (c.getDouble(c.getColumnIndex("b")));

     }while (c.moveToNext());
    }
   }

   c.close();
  } catch (Exception e) {

  }
  Db.close();

  // Here is where the problem is.  The real app has 5 fields.
  // I can pass the R.id.a
  // But how do I pass the reference to findViewById to the activity that called this

  TextView tvt4 = (TextView)findViewById(R.id.a);
  D = Fun.round( a,1,BigDecimal.ROUND_HALF_UP);
  tvt4.setText( D )  ;

   tvt4 = (TextView)findViewById(R.id.b);
  D = Fun.round( b,1,BigDecimal.ROUND_HALF_UP);
  tvt4.setText( D )  ;



 };
  • 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-19T03:24:45+00:00Added an answer on May 19, 2026 at 3:24 am

    I think I would try and keep all the UI updates within my Activity, rather than passing around TextView objects. Why not create a Bean to populate and return to the calling activity? Something like:

    public class Mybean {
        private String fieldA;
        private String fieldB;
        // create constructor and getters and setters here
    }
    

    Then populate and return the bean in your database code.

    public MyBean DisplayTop2() {
        ...
        MyBean bean = new MyBean();
        bean.setFieldA(Fun.round( a,1,BigDecimal.ROUND_HALF_UP));
        bean.setFieldB(Fun.round( b,1,BigDecimal.ROUND_HALF_UP));
        return bean;
    }
    

    Then populate the UI in your Activity:

    ...
    MyBean bean = MyDBClass.DisplayTop2();
    TextView txtA = (TextView)findViewById(R.id.mytextviewA);
    TextView txtB = (TextView)findViewById(R.id.mytextviewB);
    txtA.setText(bean.getFieldA());
    txtB.setText(bean.getFieldB());
    

    This keeps all your UI code separate from your DB code.

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

Sidebar

Related Questions

I have created a function that takes a SQL command and produces output that
Modern browsers have multi-tab interface, but JavaScript function window.showModalDialog() creates a modal dialog that
Ok, I have one JavaScript that creates rows in a table like this: function
I have created a function outside of $(document).ready() , but am still using jQuery
in my data layer class I have created a function to manually refresh the
I have a question regarding an update function I created... CREATE OR REPLACE FUNCTION
I have to create the sin function from scratch in my Comp Sci class,
I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)
Have created a c++ implementation of the Hough transform for detecting lines in images.
I have created a template for Visual Studio 2008 and it currently shows up

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.