Have tried various solutions including those in here:
Have to click a button twice for it to work in Android Studio and here:
I have to click the button twice for it to work
And have tried " android:focusableInTouchMode="false" " on the buttons in the xml file which did not work either.
My current code is as follows:
SplashActivity.java
//THIS BIT IS IN THE ONCREATE METHOD
Button enterButton = (Button) findViewById(R.id.enter_button);
enterButton.setOnClickListener(OnClick);
Button bookButton = (Button) findViewById(R.id.book_button);
bookButton.setOnClickListener(OnClick);
}
//THIS BIT IS OUTSIDE OF THE ONCREATE METHOD
private OnClickListener OnClick = new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
switch (v.getId()) {
case R.id.enter_button:
handler.removeCallbacksAndMessages(null);
startActivity(intent);
break;
case R.id.book_button:
handler.removeCallbacksAndMessages(null);
intent.putExtra("source", "onClick");
startActivity(intent);
break;
default:
break;
}
}
};
}
activity_splash.xml
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/enter_button"
android:theme="@style/AppTheme.DevButton"
android:layout_width="100dp"
android:layout_height="50dp"
android:text="Enter"
android:stateListAnimator="@null"
/>
<Button
android:id="@+id/book_button"
android:theme="@style/AppTheme.DevButton"
android:layout_width="100dp"
android:layout_height="50dp"
android:text="Book"
android:stateListAnimator="@null"
/>
</LinearLayout>
Really can't work out how to work around this!
UPDATE to - activity_splash.xml
So I've narrowed this down to the Java file, it doesn't seem to be the xml code causing the issue as I've trimmed down the xml file to the following and the symptoms are the same:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<Button
android:id="@+id/enter_button"
android:layout_width="100dp"
android:layout_height="50dp"
/>
<Button
android:id="@+id/book_button"
android:layout_width="100dp"
android:layout_height="50dp"
/>
</LinearLayout>