Click here to Skip to main content
13,006,180 members (66,079 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have declared EditText dynamically in tablerows of a tablelayout:

edittext = new EditText(Billing.this);
                            edittext.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);

to calculate input values in the EditTexts, I am using onFocusChange:

public void onFocusChange(View v, boolean hasFocus) {
        if (!pay.hasFocus()) {
            //Calculating sum of the the values of EditText areas
            //Show the EditText values with 2 decimal values
            String value = String.format("%.2f", sum);

The above code is in the class where I am making the web service call.

Also detecting the keyboard closing and I am trying to pass the focus into a dummy layout. The following code is in onCreate() method in the Activity class:

final View activityRootView = findViewById(;
    activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        public void onGlobalLayout() {
            Rect r = new Rect();
            //r will be populated with the coordinates of your view that area still visible.
            int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom -;
            if (heightDiff > 60) { // if more than 100 pixels, its probably a keyboard...
            } else {
                if (keyboardCheck == 1) {
                    keyboardCheck = 0;
                } else {
                    keyboardCheck = 1;

Now, my problem is, when I am entering some values into the edittexts, if I close the keyboard I can't edit the values of the EditText area. If I tap, it doesn't get focus or open the keyboard. Sometime if I tap for like 10/15 it suddenly gets the focus. On the other hand, after I entered some values into an EditText and press next to go to next EditText, the keyboard remains open so I can tap and edit the edittexts where I have already entered some values. So the only problem is when my keyboard is closed and I am trying to change values into an edittext box, it doesn't allow me to do that!! Please help.
Posted 6-Jul-13 15:24pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170628.1 | Last Updated 6 Jul 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100