TextView and cursor position - android

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());

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!

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.....

Android Edit Text Cursor position issues

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");

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,

Strange Behavior When Populating EditText field

I am passing a String from one activity to another, and placing it into an EditText box.
My problem is, I am placing the string "S" into the EditText box, but the cursor is BEHIND the character, instead of in FRONT of it, so the user has to hit the arrow to move the cursor so they can continue typing.
Is there a setting I need to adjust so the cursor stays in FRONT of the letter?
Try this for the edit text.
edittext.setSelection(str.length());
To set the cursor you can call:
editText.setSelection(positionOfCursor);

Categories

Resources