Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Android
I have declared EditText dynamically in tablerows of a tablelayout:
 
edittext = new EditText(Billing.this);
                            edittext.setId(800+i);
                            edittext.setBackgroundResource(R.drawable.black_border);
                            edittext.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                            edittext.setTextColor(Color.WHITE);
                            edittext.setGravity(Gravity.RIGHT);
                            param4.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                            edittext.setTextSize(12);
                            edittext.setHint("0.00");
                            edittext.setFocusable(true);
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);
            EditText.setText(value);
        }
    }
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(R.id.main);
    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.
            activityRootView.getWindowVisibleDisplayFrame(r);
 
            int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
 
            if (heightDiff > 60) { // if more than 100 pixels, its probably a keyboard...

            } else {
                if (keyboardCheck == 1) {
                    dummy.setVisibility(View.INVISIBLE);
                    dummy.requestFocus();
                    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 16:24pm

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

  Print Answers RSS
0 Kornfeld Eliyahu Peter 265
1 Sergey Alexandrovich Kryukov 202
2 George Jonsson 185
3 King Fisher 185
4 CPallini 155
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 6 Jul 2013
Copyright © CodeProject, 1999-2014
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