Android Button needs two click for action
Similar to Maves answer. This did the trick for me:
<Button
style="@android:style/Widget.EditText"
android:focusableInTouchMode="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
The question is old and I don't know whether this will solve your problem, since your pastebin link doesn't work anymore, but since I stumbled upon your post with the same problem and I found a solution I will post it anyway:
In my case the problem occured when I applied a custom style to a button following a tutorial:
<style name="ButtonStyle" parent="@android:style/Widget.Holo.Button">
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
<item name="android:clickable">true</item>
<item name="android:background">@drawable/custom_button</item>
<item name="android:textColor">@color/somecolor</item>
<item name="android:gravity">center</item>
</style>
The problem was the following line:
<item name="android:focusableInTouchMode">true</item>
Once I removed it the button worked as expected.
Hope this helps.
Old question I know. Anyways I had the same problem and needed the button to be focusable.
In the end I did use an OnTouchListener.
myButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
int action = motionEvent.getAction();
if (action == MotionEvent.ACTION_DOWN) {
// do your stuff on down here
} else if (action == MotionEvent.ACTION_UP) {
// do your stuff on up here
}
// if you return true then the event is not bubbled e.g. if you don't want the control to get focus or other handlers..
return false;
}
});
I used the following to solve a similar problem. It automatically clicks on the item again if the first click only gets focus:
input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
v.performClick();
}
}
});
I needed focusableInTouchMode to be true.