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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:58:49+00:00 2026-05-25T13:58:49+00:00

My main class has a public method called commitChanges(). My layout contains extended EditTexts

  • 0

My main class has a public method called commitChanges().
My layout contains extended EditTexts which can detect when the back button is pressed, as suggested here: Get back key event on EditText

Now, when a back button press is detected, I need to execute commitChanges, which stores the content to an array. commitChanges needs access the activity’s listview however.

The question is: how to access the commitChange function of the main activity? I will need the instance of the main activity. Heres the code of the extended EditText:

    public class BackText extends EditText{

private static final String TAG = "baby";
public BackText(Context context) {
    super(context);

}

public BackText(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public BackText(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK) && 
        event.getAction() == KeyEvent.ACTION_UP) {
            Log.d(TAG,"keypad exit");
            commitChange(this);
            return false;
    }
    return super.dispatchKeyEvent(event);
}

}

Note i’m a beginner and this pretty advanced for me.
Note 2: this has nothing to do with services/multiple activities. The BackTexts are placed in the main activity.

  • 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-25T13:58:49+00:00Added an answer on May 25, 2026 at 1:58 pm

    I solved this by adding the following sub class to my main activity class:

    class backReceiver extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(TAG,"BACK received");
            BackText bt = (BackText)tlv.findViewWithTag(EDIT_TAG);
            bt.setTag(null);//only needed for id between caller/receiver
            commitChange(bt);
        }
    
    }
    

    And adding the following to oncreate of main activity:

    IntentFilter filter = new IntentFilter(“com.commonsware.cwac.tlv.demo.commit”);

    BroadcastReceiver receiver = new backReceiver();
    registerReceiver(receiver,filter);
    

    And adding this to BackText a EditText extension:

    @Override
    public boolean onKeyPreIme(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && 
            event.getAction() == KeyEvent.ACTION_UP) {
                Log.d(TAG,"keypad exit");
                Intent intent = new Intent("com.ninovanhooff.babynames.commit");
                this.setTag("EDIT");
                getContext().sendBroadcast(intent);
                return false;
        }
        return super.dispatchKeyEvent(event);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing API implementation and my main API class has __call() magic method: public
Client has sendpoints() method which is called by some other class that I did
Like so : a class has a method called sayHello() . When a instance
I've got a class whose content is set to a layout which has a
Java Code In Java code I have class called IdentificationResult which has 3 members:
I am working in a project that has two main parts: a class library
I have a function in a class called Function , like below: public int
public class EpubReaderMainActivity extends Activity { /** Called when the activity is first created.
I have a method that contains an asynchronous call like this: public void MyMethod()
I want to create layout programmatically in different class which is not an activity

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.