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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:55:23+00:00 2026-05-30T09:55:23+00:00

I’m trying to develop a widget with an EditText (only int allowed) and KeyEvent.

  • 0

I’m trying to develop a widget with an EditText (only int allowed) and KeyEvent. The problem is when ‘0’ is pressed, It detects the KeyEvent but It doesn’t write the ‘0’ on my EditText. It should add numbers in order I press them.

et1.setOnKeyListener(new OnKeyListener() {
    @Override 
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        if (KeyEvent.ACTION_UP != event.getAction()) {
            switch (keyCode) {
                case KeyEvent.KEYCODE_0:
                    //Do something...
                    break;
                default: 
                    return false;
            }
        }
        return true;
    } 
});

I’ve tried to do something like that, but It isn’t so efficient.

et1.setText(et1.getText().toString + "0");

Do you know some kind of solution?

  • 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-30T09:55:24+00:00Added an answer on May 30, 2026 at 9:55 am

    Let me try to make myself clear Pep:

    1) If what you are trying to achieve is to have an EditText that allows only integer (numeric) input, you can add an attribute and that s it. You donT need a custom control for that behavior.

     android:inputType="number" 
    

    2) The reason why you donT get any input in your EditText is simply because you are blocking it by returning true in the overridden onKey method.

    The ref says, onKey should return:

    True if the listener has consumed the event, false otherwise.

    That means, if you are returning true, you are in charge, Android wont input anything in your EditText. Since you are not doing (at least in the code you provided) it yourself, EditText is not filled.

    So, I ll suggest you should remove the handler altogether and add the inputType attribute in xml like you did before.


    Update

    If you need to update an EditText (let’s call it EditText1) based on the input in another (EditText2), I suggest tracking the input in the first one with a TextWatcher and set the text EditText2 with the processed value.

    Check this similar issue for sample code.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.