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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:42:07+00:00 2026-06-04T12:42:07+00:00

First summary: class A extends AutoCompleteTextView { public A() { setOnKeyListner( … new OnKeyLisnter()

  • 0

First summary:

class A extends AutoCompleteTextView {
   public A() {
      setOnKeyListner( ... new OnKeyLisnter() ... ); //listener 1
   }
}
A obj;
obj.setOnKeyListener( ... new OnKeyListner() ... ); //listner 2

Is it possible to have both listeners called ? Right now I get messages only from listener 2.


I am trying to build an edit text with history derived from AutoCompleteTextView . The class has an ArrayAdapter that updates itself whenever an enter key is pressed down. So far so good. But when the object created from this class wants to do more than adding the text to a database, I need to use another onKeyListener. If it does that, the original listener will not be called. Is there a way to let both be called when enter key is pressed down?

class HistoryEditText extends AutoCompleteTextView {
    ArrayAdapter<String> adapter;
    public HistoryEditText(Context ctx) {
        super(ctx);
        setMaxLines(1);
        setOnKeyListener(new aCommand());
        List<String> myList = new LinkedList<String>();
        adapter = new ArrayAdapter<String>(ctx,R.layout.lvtext, myList);
        setAdapter(adapter);
    }
    private class aCommand implements OnKeyListener {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                    (keyCode == KeyEvent.KEYCODE_ENTER)) {
                String str = getText().toString();
                setText(" ");
                adapter.add(str);
                adapter.notifyDataSetChanged();
                return true;
            }
            return false;
        }
    }
}

Somewhere else:

   HistoryEditText cmdField = new HistoryEditText(ctx);
   cmdField.setOnKeyListener(... another listener ... )

I tried returning false in one of the listners but didn’t work. Also I don’t want to use interfaces to merge the two listeners into one.
Thanks

  • 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-04T12:42:09+00:00Added an answer on June 4, 2026 at 12:42 pm

    Similar question here might be helpful. Basically the summary is no, you can’t.

    Android – Two onClick listeners and one button

    He uses some dirty hacks to work around it, but he pretty much does exactly what you don’t want to do.

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

Sidebar

Related Questions

First i will paste my code. public class ZSEEActivity extends TabActivity { private WebView
Simple code: public class ZSEEActivity extends TabActivity { private WebView webview ; private WebView
public static class MyExtensions { /// <summary> /// Finds the missing numbers in a
Short summary : My Qt class crashes at class construction part when calling the
Most advice on thread safety involves some variation of the following pattern: public class
I'm new to anonymous classes, and today I think I ran into the first
Yesterday I wrote my first lines of code using the new dynamic type in
I have a class user which looks like this: public class User { public
I have the following HTML code: <div id=summary_form> <textarea class=summary>Please fill in</textarea><br/> <textarea class=summary>Please
I am new to EF using EF4 with Database First and generation taking place.

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.