I have very simple activity: just TextView inside ScrollView.
I want to handle user clicks and longclicks on whole ScrollView to start some action. I can easily handle click events on TextView, but cannot on ScrollView.
When text content is long enough it's not a problem, but when it's just one line of text than user needs to click that particular line (top of the screen) which is not very usefull.
How to detect click events in ScrollView? (or any other solution)
Sample activity:
public class TestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
}
public void testOnClick(View view) {
Log.d("TestActivity", "Hello? Anybody there?");
finish();
}}
And layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000"
android:clickable="true"
android:onClick="testOnClick">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="test text\n test text\n test text" />
</ScrollView>