android - textView.getSelectionEnd() returning start index value on Samsung Marshmallow 6.0 devices -


this issue observed on samsung devices android 6.0 only. working fine on other devices, including non - samsung devices android 6.0 , samsung devices android 5.1 , below.

currently don`t have samsung device android 6.0 readily check things on it, arranging soon.


the feature using :

the user long presses on word sentence in textview , user can edit selected word.


we accomplish :

  • making textview selectable , adding longclicklistener.
  • adding custom selection action mode callback , overriding oncreateactionmode() return false, since don`t need default cut-copy-paste action mode.
  • handling onlongclicklistener exact selected word , provide ui correct , replace word.

the issue facing :

textview.getselectionstart() returns correct start index textview.getselectionend() returns value of start index instead of end index. have guard condition whenever start , end index same selection space , hence ignore it, word selections on samsung devices android 6.0 , ignored resulting feature failure.


things tried :

  • we tried replacing actionmode.callback actionmode.callback2 mentioned under "text selection" section on page android 6.0 changes didn`t in fixing issue.
  • tried searching samsung setting available related text selection, clipboard etc no luck. know can lame option not take chances samsung touchwiz. did found setting alter delay touch selection ranging 0.5 2.0 seconds.

the code snippets :

tvtext.setcustomselectionactionmodecallback(new actionmode.callback() {         @override         public boolean oncreateactionmode(actionmode mode, menu menu) {             return false; // true = create actionmode         }          @override         public boolean onprepareactionmode(actionmode mode, menu menu) {             return false;         }          @override         public boolean onactionitemclicked(actionmode mode, menuitem item) {             return false;         }          @override         public void ondestroyactionmode(actionmode mode) {         }     });      tvtext.setonlongclicklistener(new view.onlongclicklistener() {           @override         public boolean onlongclick(view v) {              final textview textview = (textview) v;             new handler().postdelayed(new runnable() {                  @override                 public void run() {                      //this works correct on devices android 6.0                     int startindex = textview.getselectionstart();                      //this works wrong on samsung devices android 6.0, result same getselectionstart()                     int endindex = textview.getselectionend();                      //the guard condition ignore empty selections                     if ((endindex - startindex) <= 0) {                         return;                     }                      // bunch of things ui applying different foreground colors selected word, striking out selected word etc.                 }             }, text_long_press_delay);             return false;         }     });  

the xml code textview , it`s style :

<textview     android:id="@+id/tvtext"     style="@style/stylechatbubbletext"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginbottom="2dp"/>  <style name="stylechatbubbletext">     <item name="android:layout_width">wrap_content</item>     <item name="android:layout_height">wrap_content</item>     <item name="android:textsize">16dp</item>     <item name="android:textcolor">@color/text_black</item>     <item name="android:textisselectable">true</item>     <item name="typeface">roboto_regular</item> 


any regarding issue appreciated.

check build version if buildversion >= 6 return true , implement floating toolbar custom layout. if buildversion <6 return false, use current implementation


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -