0

I have a calculator app.

I show the input and result in an EditText component...

And below I have a million buttons containing the numbers 0 through 9 and tons of functions and operations... INSIDE a scrollview.

the edittext component is fixed up at the top of the window, although the user may scroll down to see more buttons and functions ...

Whenever I open the app, the keyboard appears. I reckon that means that some kind of pointer is always going up at the EditText component and hence opening up keyboard.

I used EditText instead of TextView since some people might prefer to enter some stuff through their keyboard, but thats a minority .

I don't want to force it on them , If I'm getting annoyed pressing back button to drive away the keyboard - I sure as hell don't want to show the users the same.

I know I can just change it to a normal TextView, but if the app could open and simply not cause the keyboard to open(indirectly,by setting the pointer to the EditText) -That would be perfect .

Any idea how to do that ? I have never even heard about anything related to this ....

2 Answers2

0

To remove the immediate focus on the EditText when starting the application, use this:

 public void hideSoftKeyboard(View v) {
        Activity activity = (Activity) v.getContext();
        InputMethodManager inputMethodManager = (InputMethodManager)  activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    }

Just paste this in the main activity.

See if it works, as it worked for me.

Cheers

g00dy
  • 6,752
  • 2
  • 30
  • 43
  • Not Working ! , I pasted into the Main Activity class, but the keyboard still opens up.. :( Do I need to call it in the OnCreate() too ? if so.. How ? what should be the parameter ?... or anything else ? –  Jul 30 '13 at 09:34
  • Nevermind ! , Anil's answer worked ! shorter and easier too :) –  Jul 30 '13 at 09:39
0
<activity android:name=".YourActivity" android:windowSoftInputMode="stateHidden"  />

Add this to your manifest file...Try this...

Looking Forward
  • 3,579
  • 8
  • 45
  • 65