Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeger committed Sep 14, 2016
1 parent 7886ce5 commit 6275b05
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public SelectableTextHelper(TextView textView) {
}

private void init() {
mTextView.setText(mTextView.getText(), TextView.BufferType.SPANNABLE);
mTextView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Expand Down Expand Up @@ -187,6 +188,9 @@ private void show(int x, int y) {
if (mTextView.getText() instanceof Spannable) {
mSpannable = (Spannable) mTextView.getText();
}
if (mSpannable == null || startOffset >= mTextView.getText().length()) {
return;
}
selectText(startOffset, endOffset);
showCursor(mStartHandle);
showCursor(mEndHandle);
Expand Down Expand Up @@ -274,7 +278,7 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
hideSelect();
selectText(0, mTextView.getText().length() - 1);
selectText(0, mTextView.getText().length());
isHide = false;
showCursor(mStartHandle);
showCursor(mEndHandle);
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
android:id="@+id/tv_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:bufferType="spannable"
android:layout_margin="16dp"
android:lineSpacingExtra="3dp"
android:text="@string/long_text"
android:textSize="16sp"/>
Expand Down

0 comments on commit 6275b05

Please sign in to comment.