Skip to content Skip to sidebar Skip to footer

Android Button Always Takes Two Clicks To Fire Onclick()

I have a RelativeLayout inside of a ScrollView that contains a Button and some TextViews and EditTexts. In my xml layout file, I am defining android:onClick but it always takes t

Solution 1:

OK, I found it. It was, of course, my own mistake. At the end of my onCreate method I was doing this:

// Set the focus to the calculate button so the keyboard won't show up automatically ButtoncalcButton= (Button)findViewById( R.id.ac_button_calculate );
calcButton.setFocusable( true );
calcButton.setFocusableInTouchMode( true ); 
calcButton.requestFocus();

So of course, no matter what I did in my xml file, I was overriding it in my code. Instead, I used this to hide the keyboard:

getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN );

Which works great.

Post a Comment for "Android Button Always Takes Two Clicks To Fire Onclick()"