Home » Android » How to make seekBar bubble onClick

How to make seekBar bubble onClick

Posted by: admin November 1, 2017 Leave a comment

Questions:

I want the parent view to reset a timeout every time the user touch on the views inside a container view. It works well except for the seekBar View that doesn’t bubble any click.

Update:

The listener is set at the parent view like this:

  this.setAddStatesFromChildren(true);//has no effect

  this.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.d(TAG, "reset hide timer: ");
            handler.removeCallbacks(hideCallback);
            //playerControls is a compound view
            playerControls.setVisibility(VISIBLE);

            handler.postDelayed(hideCallback, 5000);
        }
    });

This code catch all events from the child views but fail to get events from the seekbar inside the playerControls view. The view have other components that bubble events, just not seekbar.

The parent view:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bar">

<android.support.v7.widget.AppCompatImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/show"
    />

<..PlayerControls
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/player_controls"
    android:layout_below="@id/show"
    android:visibility="gone"
    />

</RelativeLayout>

and the child view (PlayerControls):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/player_controls"
    >

    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/duration"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

    <android.support.v7.widget.AppCompatSeekBar
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:id="@+id/seek_bar"
        />

</RelativeLayout>
Answers: