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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:52:20+00:00 2026-05-24T23:52:20+00:00

I want to update a TextView in main activity from inside a custom object.

  • 0

I want to update a TextView in main activity from inside a custom object.

The custom object is a number picker written from scratch. It has an EditText and 2 button (+/-).
My purpose is that when a user press the + or – button the TextView will be updated with that value.

Now i can think 2 possible solutions:

  1. The custom object update the TextView when the + or – button is pressed (inside the onClickListener).
  2. I define another class that extend the custom picker, with the logic for update the textview.

But my problem is that i want to keep the textView logic outside the custom picker (so if is possible to have the update function inside the activity).
There is a solution to that problem?

The custompicker xml code is that:

<org.croncalc.MyPicker android:id="@+id/hourpicker"
                android:orientation="vertical"
                android:layout_width="65dp"
                croncalc:maxnumber="24"
                croncalc:minnumber="1"
                croncalc:step="5"
                croncalc:cycle="true"
                android:layout_height="wrap_content">

Here a screenshot

I want that everytime one of the picker change its value the textview on the right corner will be updated.

If useful here the onClick() code for the +/- buttons:

    OnClickListener clickListener = new OnClickListener() {
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.decbtn:
            step(-1);
            break;
        case R.id.incbtn:
        default:
            step(1);
            break;
        }
    }                   
};

private void step(int step) {
    current += step;
    if (step > 0) {
        decButton.setEnabled(true);         
        if ( current > maxNumber) {
            if(cycle){
                current-=maxNumber;
            } else {
                current=maxNumber;
                incButton.setEnabled(false);
                incButton.setPressed(false);
            }           
        }
    } else {
        incButton.setEnabled(true);
        if ( current < minNumber) {
            if(cycle){
                current+= maxNumber;
            } else {
                current=minNumber;
                decButton.setEnabled(false);
                decButton.setPressed(false);
            }                       
        }
    }
    pickerText.setText(Integer.toString(current));      
}

Thanks in advance.
Ivan

  • 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-24T23:52:21+00:00Added an answer on May 24, 2026 at 11:52 pm

    Ok i answer myself (i found a solution).

    I define a CustomListener for my objcet.
    I declared an interface called:
    package org.croncalc;
    public interface OnMyPickerChangeListener {
    public abstract void onMyPickerChanged(String srcTxt);
    }

    and then i added in MyPickerClass (this is the name of the object) a new class Variable:

    OnMyPickerChangeListener onMyPickerChangeListener;
    

    That variable will be initialized at null.
    After i defined in MyPicker two new methods:

    1. The first is the setOnMyPickerChangeListener with that method i can add a OnMyPickerChangeListener:

      public void setOnMyPickerChangeListener(OnMyPickerChangeListener listener) {
      onMyPickerChangeListener = listener;
      }

    2. The second method is onMyPickerChanged, that method will be called everytime we want to trigger the Change Event:

      private void onMyPickerChanged(){
      if(onMyPickerChangeListener!=null){
      onMyPickerChangeListener.onMyPickerChanged(pickerText.getText().toString());
      }
      }

    Now in the main activity i declared a new OnMyPickerChangeListener and implemented the interface method onMyPickerchanged:

    OnMyPickerChangeListener pickerListener = new OnMyPickerChangeListener() {
    
        @Override
        public void onMyPickerChanged(String srcTxt) {          
            localTv.setText("Value: " + srcTxt);
        }
    };
    

    And i added that Listener to the Picker:

    minutesPicker.setOnMyPickerChangeListener(pickerListener);
    

    And now it works 🙂

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

Sidebar

Related Questions

Is there a way to get value from textView item inside widget ? I
I have a custom listView with a textView, editText and a Button on a
I have the following app that has a textview and an edittext. When the
I want update a column by adding days to current time. In pseudosyntax it
I want to update a list of storage devices as the user inserts USB
I want Windows Update to automatically download and install updates on my Vista machine,
I want to update two columns in a table. The value of the second
I want to update/upgrade the standard Leopard install of Sqlite3 to >3.5 to use
i want to update my sqlite database but i cannot find the way to
I want to update some file in a server, with an automated script and

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.