Android Edit Text Cursor position issues - android

I am making a text editor in android, I am using a multi-line edit text that holds all the text and all the editing is done on the same edit text.
I have one issue:
When i started working on the application, the cursor kept on the first position of the edit text. every time i use to enter text, the cursor did not move, rather the text kept on adding.
then i used this short piece of code to bring the cursor at the end of the edittext
edittext.setSelection(edittext.getText().length());
Now the problem is that i am unable to edit any text that has already been written in the edittext, as when i ever i try to edit it, the cursor jumps to the last position.
What i want is that my cursor should move to the position where i want to add or edit text. it is not allowing me to do that right now.
Additional things:
I am using a text watcher and all of the functionalities are being implemented in the text watcher. secondly i am using post function in onResume of my activity to implement certain functionalities.

use append method for this, it will show the cursor at the last :
etEditText.append("Text here");

Related

Could both cursor and all text selected be there at the same time in an EditText?

When I tap on an EditText, I would like to have all text selected along with the cursor at the end. How can this be achieved?
In my layout xml, I have
android:selectAllOnFocus ="true"
and I am setting the cursor using
editText.setSelection(). The full text gets selected, but I am not able to get the cursor at the end of the text.
I checked the android documentation for setSelection here and it looks like the right API to show cursor at a specific position.
Could someone please help. Thanks!

Empty BulletSpan issue in android Edittext

I'm implementing a rich text editor. In that, when user clicks on bullet icon in toolbar, an empty bullet should be created with no character in it. But I can not achieve this by setting span on the cursor position. I have to add an unwanted space to do this. Using below code,
editable.insert(cursorPos, " ");
editable.setSpan(new BulletSpan(), cursorPos, cursorPos + 1,Spanned.SPAN_INCLUSIVE_INCLUSIVE);
I have also tried with LeadingMarginSpan but same result. I am getting the required feature, if the cursor is placed in first position of EditText or there is any text in that line. Also same problem persists in Numbered list also.
And the problem persists only for first bullet/Number in list. In subsequent bullet or numbered list item the span is working properly.
Can you please anyone help me how to implement empty bulletspan without any space or character ?
Thanks in advance...

Set position of edit text cursor based on user touch position Android

I try to make some kind like note application in android xperia or samsung galaxy...
What I wanna do is to set the cursor of edit text position follow the touch position from user.
In normal edit text whenever we touch the edit text area, cursor will always positioned at the end of our characters or between the characters..
So The notes is some kind like being appended with many characters so we can move the cursor wherever we want...
I've tried to appended many blank spaces. but it wont help... Cursor only can move on 1 line only..
Is there any solution for this?
Thanks before.....

TextView and cursor position

I have a TextView and number buttons to type inside the TextView like a calculator.
I need to keep the cursor to stay in its place when I am typing the numbers and NOT to move.
For example lets say this is the cursor "[" , so this is what's happening now:
[12345
What I want when I am typing the numbers
12345[
This numbers are just an example, what is important for me is the cursor stay at the right and not to move.
Update:
[12345 the first number what I typed is 5 and the last one is 1.
For EditText you can change the cursor for the view. If you are currently manipulating the cursor position in your TextView, then you can do something similar in the code if need be. There might be an automated way to do so, but I had thought setting the gravity as others had mentioned would do the trick.
EditText editText = (EditText)findViewById(R.id.calculatorEditTextView);
editText.setSelection(editText.getText().length());

Android: Not able to move the cursor along text on EditText

I have a multiline edittext field. I can write everything but when I try to go back and put the cursor on a given position I am not able to do it. Instead the cursor goes to the start of the text and never moves from there again.
NOTE; My text is only one long 'word'. A sequence of HEX characters.
Thanks in advance,

Categories

Resources