I have an android loyout like this:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/scrollview">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
How can I register a context menu so that it will pop up when user long press anywhere in the scroll view?
I have tried find the scrollview and and register context menu for that:
ScrollView scrollView = findViewById(R.id.scrollview);
registerForContextMenu(scrollView);
But that does not, I don’t see any context menu pops up. The only way works is if I register my text view for context menu.
But that may cause bad experience since my text view sometimes can be short (1-2 lines/1-2 words) and sometimes it can be long (mult sentences).
What is the best way to fix this?
A few ideas:
Set the scrollview to be long clickable (might be false by default, not sure)
If that doesn’t work, set your own OnLongClickListener, and from within it, manually call ScrollView’s showContextMenu method.