I have a button:
<Button
android:id="@+id/my_btn"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="My Button"
android:textColor="@android:color/black"
android:textSize="20sp"
android:textStyle="bold" />
And in my activity I set an onclicklistener:
findViewById(R.id.my_btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
handleButtonClick();
}
});
In spots in my code I set the button's visibility to View.INVSISBLE and then back again to View.VISIBLE. When it goes from invisible to visible and I try to click on it, it sometimes takes several clicks before the onclicklistener actually receives the event. Meanwhile whenever I click on it and nothing happens, logcat records this every time:
D/ViewRootImpl@1b16f49[MainActivity]: ViewPostImeInputStage processPointer 0
D/ViewRootImpl@1b16f49[MainActivity]: mHardwareRenderer.destroy()#4
D/ViewRootImpl@1b16f49[MainActivity]: dispatchDetachedFromWindow
W/InputEventReceiver: Attempted to finish an input event but the input event
receiver has already been disposed.
D/InputTransport: Input channel destroyed: fd=71
Once the button click event is actually received, every other click on the button works until its made invisible and back to visible again.
What should I do to ensure the button click event is always recieved and handled?