2

I'm trying to implement a clickable scrollview:

findViewById(R.id.parent_view).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("", "onClick");
            }
        });  




         <LinearLayout
            android:id="@+id/parent_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:clickable="true">

           <ScrollView
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_gravity="left|center_vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="" />

           </ScrollView>

           <ScrollView
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_gravity="left|center_vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="" />

           </ScrollView>
        </LinearLayout>

It seems like the scrollview consumes all touch events and therefore the onClick method is never triggered. Is there any way to maintain the scrolling functionality and also make it clickable?

1
  • What is the purpose of the linear layout here? It looks useless. I certainly have scrollviews that contain linearlayoits that contain clickable buttons working fine. I'd you want to respond to the user clicking the scrollview, then bin the linear layout and at the onclick listener to the scrollview. Click event may get consumed by the recycles thoigh, but there is a way round it Commented Mar 6, 2014 at 6:53

2 Answers 2

2

Can you please specify in more detail where exactly you want to handle click event. As per your code you are handling click event on Linear layout. Below post may help you.

How can I set attribute onClick to a ScrollView?

Sign up to request clarification or add additional context in comments.

Comments

0

Try setting the android:clickable="false property to each child of the ScrollView for the onClickListener

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.