Hello chums!
I've been having this problem, you see; and it has to do with the
cursor and Selection.
Preamble:
I've looked in several places for this answer including:
developer.android.com, anddev.org, this group, and #android-dev on
irc.
Target firmware is 1.5 (API 3)
What resources are being used:
EditText (android.widget.EditText)
Custom input with buttons (android.widget.Button)
What I'm trying to do:
Update an int that holds the position of the cursor after it's been
changed by:
A. Touch input
B. Trackball input
C. Custom button input
What I've tried:
EditText.onTouchEvent() and EditText.onTrackBallEvent()
update the Selection.getSelectionEnd();
This doesn't seem to ever grab the actual position of the cursor.
The colsest I've gotten to solving this is:
Selection.getSelectionStart(EditText.getText())
But that reads the cursor position in a Button.OnClickListener(). And
even then it just reads the position of where the cursor has been
moved to through touch/trackball, then moves it back to the start of
the EditText.
Example:
EditText out = (EiditText)findViewById(R.id.textOutputArea);
String str = "";
Button zero;
zero = (Button)findViewById(R.id.Zero);
zero.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
str += "Zero";
// This get's the position of the cursor.
//*see note below this code
out.setText(str + "\n" +
Selection.getSelectionStart(out.getText()));
}
});
So the out.setText(...); gets prints:
Zero
0
because the cursor is at index 0, but when you navigate the cursor by
touch or trackball to the end of the string and press the zero button
again, you get:
ZeroZero
4
Because the cursor is at index 4.
Now I can't figure how to read that position on/in/during/after
trackball or touch events. Any thoughts?
Thank you for any help on this. It's been a real bugger to figure out.
Cheers!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en