how to NOT select all on EditText long click - android

When the user long-touches/long-clicks in the EditText, my app always selects all text. How do you instead make the EditText not select all, and instead select only the user-selected text?
I read Select all text inside EditText when it gets focus
then tried explicitly setting android:selectAllOnFocus="false"but that is not working. Double tapping or any other click length doesn't work either.
To override OnLongClickListener might work, but I don't know how to get the user's start and end selected index.

For those who are coming across this question in the future, the (or at least a) solution is to add the textLongMessage option to android:inputType:
<EditText
...
android:inputType="textLongMessage" >
<!-- Or you might have multiple input types -->
<EditText
...
android:inputType="textLongMessage|textMultiLine|textNoSuggestions" >
This will make the EditText's behavior be to select a single word from the text.

Try reading these liknks and see if they help:
how to NOT select all on EditText long click
how to NOT select all on EditText long click
You can try in your main.xml file:
android:selectAllOnFocus="true"

Related

how to get whole text selected onClick EditText

In a browser we click on search box whole text got selected. like that how to enable this in android EditText. When click on EditText, whole text in it got selected.
Its my first question so please don't critic it.
editText.setSelectAllOnFocus(true);
You can add it in EditText
android:selectAllOnFocus="true"
Use android:selectAllOnFocus
If the text is selectable, select it all when the view takes focus.
May be a boolean value, such as "true" or "false".
From XML
android:selectAllOnFocus="true"
FROM java
YourEditText.setSelectAllOnFocus(true);

android - handle virtual keyboard enter key behaviour

I have five edittext in my layout. by default when i click on any of the edittext the virtual keyboard shows like following
Is it possible to modify the behavior of enter key ? I want when the key pressed the focus should be transferred to next edit text. Keyboard should look like
notice the change in enter key and also suggestions are disabled. Is there any way to achieve it ?
To disable text suggestions, add the following parameter to your EditText:
<EditText
android:inputType="textNoSuggestions"
(…)
/>
And to go to the next field upon pressing "enter" add the ID of the next field on the following parameter:
<EditText
android:nextFocusForward="#+id/nextEditTextId"
(…)
/>
Details can be found here.
Hope it helps!

how to select a word in android textview

how can i get the exact value of the specific word in a textview when:
1 - the user had taped the word (the word can be just one of many in some text chunk),
2 - the textview has in its xml layout, android:textIsSelectable="true" ,
so by default android lets the user to highlight a specific word
and opens a small menu(copy, paste, share). can i manipulate this menu or maybe add more options to it in order to extend it and do something i want with the highlighted word?
i need to get the exact word based on some interaction with the user(click , tap, select....)
i didn't find any straight forward answer. is it even possible?
(i have android htc one x)
Thanks.
A more suitable component to use for your scenario is EditText.
It is declared like this in your manifest file:
<EditText
android:text=" This is not an editable EditText"
android:id="#+id/EditText01"
android:layout_width="wrap_content"
android:textColor = "#android:color/white"
android:editable = "false"
android:cursorVisible="false"
android:layout_height="wrap_content"
android:background = "#android:drawable/dark_header">
</EditText>
Then, it is only two lines of code to get the selected text:
EditText et = (EditText)findViewById(R.id.title);
String selectedText = et.getText().substring(et.getSelectionStart(), et.getSelectionEnd());
Here, we assumed that the text was selected from left to right. If it was selected from right to left, then above would result in an exception so you can avoid that by checking if start position is higher than the end position.

How to allow the user to select a text range in a TextView (Similar to EditText)

I've got a TextView that I would like to allow the user to select a range of text from within it. The TextView takes up the entire width and height of the device (minus some padding and a title at the top). In an EditText if you long-click you get a selection overlay that allows you to set your selection left and right bounds. I'd like this functionality in a TextView. I've read that in API level 9 (2.3) (http://developer.android.com/sdk/android-2.3.html) there are new text selection controls, but I'm having difficulty implementing this. I'm doing this right now:
eic = new InputConnection( bookTextView );
eic.beginBatchEdit();
But it doesn't do anything noticable. Does anyone know how to use InputConnection correctly? Thanks.
Edit: I don't necessarily need to use what I was attempting above. I ultimately want to use either a TextView or an EditText which looks and feels like a TextView and be able to select text using a dragging cursor. Then I would like to manipulate the selected text with various context menu options (or a menu that pops up above the selected text).
Here is an idea.. Add an EditText with a TextView background, Here is an example
<EditText
android:text=" This is not an editable EditText"
android:id="#+id/EditText01"
android:layout_width="wrap_content"
android:textColor = "#android:color/white"
android:editable = "false"
android:cursorVisible="false"
android:layout_height="wrap_content"
android:background = "#android:drawable/dark_header">
</EditText>
add this to your xml in the place of TextView
You can enable the TextView's Spannable storage. See Highlight Text in TextView or WebView for an example.
See also:
http://developer.android.com/reference/android/text/Spanned.html
You could display the text in a WebView and enable text selection. If you want to only use a textview/edittext, here is an answer that might help you and here is information on the Spannable class that might help you accomplish what you want.
Actually, you do not have to develop this feature by yourself. You just need to use EditText instead TextView, while you set the android:editable of EditText to false. My idea is the same as sandy's.
My code is here, hope it may help you:
https://stackoverflow.com/a/11026292/966405
After long internet surfing to find a solution, i prefered create my own class
https://github.com/orionsource/SelectableTextViewer
Goal features:
Easy to use - only one class
Support for text and Html.fromHtml
Can be in ScrollView with correct touches
Cursors can be redefined
Color of selection can be redefined
All the above solutions either too long or not working for me.
What you need is to add just textView.setTextIsSelectable(true)
in your activity or fragment or adapter.

Android EditText

in my custom listview that Contain an image and EditText ,and in EditText i can comment the photo ,i can give text comment max length of 50 ,when i lost the focus in EditText i want to rearrange the text in EditText in following format
EG: suppose comment contain 40 char and user can at a time directly view only 20 char,then if i lost the focus text should be rearranged that at the end there should be 3 dot
Original Comment i wirte:eg-> eeeeeeeeeeeeeeeeeeeeeeeeeee
after i lost focus it should shown as-> eeeeeeeee...
it's importent that the nothing happens to original text because these text i want to send to server, and i directly take these values,and if am replace the text by new this type of text this will create problem, also when i gain focus i need to see full text also.
NB: i set android:singleline=true
Try android:ellipsize="end", or if you want to fade, try android:fadingEdge="horizontal"
Use the android:ellipsize="end" in you XML layout file. You can also show the scrolling text by using android:ellipsize="marquee".

Categories

Resources