How to stop EditText from gaining focus at Activity startup in Android

I have an Activity in Android, with two elements: EditText ListView When my Activity starts, the EditText immediately has input focus (flashing cursor). I don’t want any control to have input focus at startup. I tried: EditText.setSelected(false); EditText.setFocusable(false); No luck. How can I convince the EditText to not select itself when the Activity starts? 5 … Read more

How do you close/hide the Android soft keyboard programmatically?

I have an EditText and a Button in my layout. After writing in the edit field and clicking on the Button, I want to hide the virtual keyboard when touching outside the keyboard. I assume that this is a simple piece of code, but where can I find an example of it? 12 125

Converting a string to an integer on Android

See the Integer class and the static parseInt() method: http://developer.android.com/reference/java/lang/Integer.html Integer.parseInt(et.getText().toString()); You will need to catch NumberFormatException though in case of problems whilst parsing, so: int myNum = 0; try { myNum = Integer.parseInt(et.getText().toString()); } catch(NumberFormatException nfe) { System.out.println(“Could not parse ” + nfe); }