0

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>
Community
  • 1
  • 1
Daveak
  • 3
  • 1
  • 3

3 Answers3

0

I would normally extend SplashActivity to include View.OnClickListener and implement

Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(this);

@Override 
public void onClick(View view_) {
    ...
}

Not sure if this would make a difference or not?

Nathan Headley
  • 152
  • 1
  • 13
  • This was initially how I had it actually, I changed it to how it is now to see if it would work and no joy either way I'm afraid. Thanks for the suggestion though. – Daveak Nov 15 '16 at 14:46
0

I think the focus is the parent view so add the android:descendantFocusability= attribute to your parent view

SaravInfern
  • 3,338
  • 1
  • 20
  • 44
  • Tried this by putting 'android:descendantFocusability="blocksDescendants"' on the LinearLayout, on the buttons themselves, on the RelativeLayout and it didn't quite do it I'm afraid. Is there somewhere else in the code I should put it ? – Daveak Nov 15 '16 at 14:41
  • Also tried `android:descendantFocusability="afterDescendants"` on the parents which didn't work either I'm afraid. – Daveak Nov 15 '16 at 15:04
0

So after all of the testing I've managed to find out what the problem was.

It was this line of code here which helps with display the image as full screen:

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

The SYSTEM_UI_FLAG_HIDE_NAVIGATION flag does not register touch events so you need to change it to SYSTEM_UI_FLAG_IMMERSIVE so it reads as follows:

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE);

Note however this flag was only released after Android 4.4 API Level 19 so won't work in Android versions before this.

Thanks guys for looking into this as well for me, most appreciated.

Daveak
  • 3
  • 1
  • 3