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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:41:23+00:00 2026-05-27T22:41:23+00:00

I have searched to find a solution to this problem without anyluck. I have

  • 0

I have searched to find a solution to this problem without anyluck.

I have a simpe android app that the user enters a number into one editText (@+id/incBox) field and a given percentage of the that number is automatically placed into another editText (@+id/excBox).

I have implemented a setOnKeyListener for both editText fields, that gets the entered number and does the calculation to update the other field (vice versa).

This code works fine in the emulator everytime a digit is entered the other editText field is updated . However when running the apk on my samsung galaxy s2 the other field is not updated. For the other field to be updated on the phone you have press Enter on the softkeyboard. What am I missing here? I have even removed the event.getAction() == KeyEvent.ACTION_UP “if” clause to ensure no CANCEL or MULTITOUCH events affect the OnKey listener. How do I get to this to work on the phone?

Another problem that I am experiencing is that after entering a value into a field. Moving to the other field and deleting or pressing enter is quite laggy. Sometimes there is a 0.5 second delay when pressing the backspace button to delete a digit in an already populated field. Is this because of the try catch?

Any help would be appreciated.

this is the main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:gravity="top"
    android:background="@drawable/bground"
>

    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:text="@string/inclusive"
    android:textSize="20px"
    android:paddingTop="10px"
    android:textStyle="bold" />


    <EditText
    android:id="@+id/incBox"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="numberDecimal" 
    android:layout_gravity="center_horizontal"
    android:layout_marginLeft="25px"
    android:layout_marginRight="25px"
    android:singleLine="true"
    >
    <requestFocus />
    </EditText>


    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="20px"
    android:textStyle="bold"
    android:gravity="center_horizontal"
    android:text="@string/exclusive" />

    <EditText
    android:id="@+id/excBox"
    android:layout_width="fill_parent"
    android:layout_height="60px"
    android:inputType="numberDecimal" 
    android:layout_gravity="center_horizontal"
    android:layout_marginLeft="25px"
    android:layout_marginRight="25px"
    android:singleLine="true"
    >
    </EditText>
</LinearLayout>

and here is the activity.java

public class PercentageCalculatorActivity extends Activity
{

private EditText inclusive;
private EditText exclusive;
DecimalFormat cost = new DecimalFormat("0.00");

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    // Set Activity Layout
    setContentView(R.layout.main);

    // Get the EditText and Button References
    inclusive = (EditText)findViewById(R.id.incBox);
    exclusive = (EditText)findViewById(R.id.excBox);

    //Set KeyListener to ourself
    inclusive.setOnKeyListener(new OnKeyListener() 
    { 
 public boolean onKey(View v, int keyCode, KeyEvent event) 
      { 
        try
        {

         double num = Double.parseDouble( inclusive.getText().toString() );

        if ( num > 0)
        {                           
          num = num * 0.25;
        String exc = cost.format(num).toString();
        exclusive.setText(exc);
            }

    // Close the keyboard on enter press                                    if ( keyCode == 66  )                           {
    InputMethodManager imm = (InputMethodManager)getSystemService    (Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(inclusive.getWindowToken(), 0);
    }

            return false;
            }
            catch (Throwable e)
                {
                // set other field to empty if this field is also blank
    exclusive.setText("");
                        return false;
                }            
        }
    });

   exclusive.setOnKeyListener(new OnKeyListener() 
    { 
        public boolean onKey(View v, int keyCode, KeyEvent event) 
        { 
            if(event.getAction()==KeyEvent.ACTION_UP ) 
            { 
                try
                {
                    double num = Double.parseDouble( exclusive.getText().toString() );

                    if ( num > 0)
                    {
                        num = num * 4;
                        String exc = cost.format(num).toString();
                        inclusive.setText(exc);
                    }

                    if ( keyCode == 66  )
                    {
                        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(exclusive.getWindowToken(), 0);
                    }                   

            return false;
                }
                catch (Throwable e)
                {
                    // set other field to empty if this field is also blank 
                                inclusive.setText("");
                    return false;
                }

            }
            else
            {
                return false;
            }

        }
    });
  • 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-27T22:41:24+00:00Added an answer on May 27, 2026 at 10:41 pm

    It actually depends not on the device but on the keyboard you select. I’ve run into this before. If you swap out the keyboard for a different one, you’ll find that suddenly it starts reacting as you expect. I’m not sure what the cause of this is, but you should give that a try and see if that solves your issue.

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

Sidebar

Related Questions

I have searched online for a solution, but have yet to find one that
I searched the site but I could not find any solution to this problem.
I've searched for two days trying to find a solution to this. My problem
I have searched a long time and cannot find a solution to my problem.
I searched around and couldn't find a solution to this problem. I am trying
I have searched all around to find a solution to my problem, but i
I searched this problem in the site, but I couldn't find a solution. I
I cannot find a solution with this problem. I have to join TWO MVC3
I have searched on this forum and haven't been able to find a solution
I have searched around, and it seems that this is a limitation in MS

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.