3

As the title say I am trying to have a EditText field that takes more or less the whole screen. That's not a problem to do, but the problem is when you start write then it start's in the midle of the screen. And you can't select where to write. what I try to achieve is to make it to be like a note. That I can write where I select, anyone know how to make this work:)? thank's!

Hans Fredrik
  • 235
  • 1
  • 2
  • 8
  • Thank's for the feedback mate! Yeah that makes it go top in the left corner. But let's say I have a editText that is 400dp height and I want the it to be like whatever line you click you can start to write. As it is you have to click(enter) to get to the next line. Do you get my point? – Hans Fredrik Nov 01 '12 at 15:49

1 Answers1

1

You should be able to do this by

  1. Implementing an onTouch listener for the EditText (but make sure you do not consume the event).
  2. Find where you touched the screen via the event's getRawX and getRawY methods.
  3. Set the EditText's android:padding according to the coordinates you selected.
Ernir
  • 333
  • 1
  • 8
  • 17
  • Thank's Ernir, I get the part where I am supposed to make a TouchListener, But how exactly am I supposed to get the rawX and the rawY and set the padding for the EditText? – Hans Fredrik Nov 01 '12 at 16:11
  • Or I can't find the method getRawY and getRawX, is it mehtod that's called that ? – Hans Fredrik Nov 01 '12 at 16:14
  • Once you have an event, you can call `getRawX`on that event [like in this thread](http://stackoverflow.com/questions/2939332/get-the-co-ordinates-of-a-touch-event-on-android) (although with getX/getY rather than getRawX/getRawY. You could use those too). [This](http://stackoverflow.com/questions/9685658/add-padding-on-view-programmatically) would be an example of how you can programmatically set a view's padding. – Ernir Nov 01 '12 at 16:23
  • I know how to getRawX() and getRawY() the problem is the numbers from getRaw is float and setPadding only takes int. Do I misunderstand how to do it? – Hans Fredrik Nov 02 '12 at 08:47
  • 1
    You can cast the number from float to int. The expression `(int) theFloatNumber` would return an integer approximation of the float. – Ernir Nov 02 '12 at 11:29
  • Thank's Enir! I understand it now, but I don't get it to work right, feel a little bit dumb now. The problem is that the whole text changes the position, and i only want when Im clicking above or down on the edit text field it change the line. do you know how to do it ? – Hans Fredrik Nov 02 '12 at 14:33
  • No problem mate:)! you made me learn some new stuff, so it was very helpfull anyway! So thank's! – Hans Fredrik Nov 03 '12 at 15:10