Reputation: 10129
I am using a TextView in my application. Here is the XML for that component.
<TextView
android:id="@+id/txt_MyText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:textSize="90px"
android:textIsSelectable="true"
android:fadeScrollbars="false"
android:text="@string/dummy_text"/>
Now in my code, I am setting movement method for my TextView using this code,
txt_MyText.setMovementMethod(new ScrollingMovementMethod());
After setting the movement method, text view fails to make a selection of Text when user long presses the TextView. In Logs, I can see this message,
TextView does not support text selection. Selection cancelled.
But if I remove the movement method code the TextView continues to allow selection.
What's going wrong here?
Thanks
Upvotes: 3
Views: 1850
Reputation: 3350
The issue here is the focus. The Android Doc has the explanation here:
void setMovementMethod (MovementMethod movement)
Sets the MovementMethod for handling arrow key movement for this TextView. This can be null to disallow using the arrow keys to move the cursor or scroll the view.
Be warned that if you want a TextView with a key listener or movement method not to be focusable, or if you want a TextView without a key listener or movement method to be focusable, you must call setFocusable(boolean) again after calling this to get the focusability back the way you want it.
EDIT
I believe it could be how you are setting your TextView's movementMethod.
Try it like so:
myTextView.setMovementMethod(ScrollingMovementMethod.getInstance());
Upvotes: 1
Reputation: 587
try
txt_MyText.setTextIsSelectable(true);
txt_MyText.setFocusable(true);
txt_MyText.setFocusableInTouchMode(true);
Upvotes: 0