A artiechappie Member Licensed User Longtime User Jan 17, 2012 #1 Hi Guys, I'm a relative newbie here but I have a question relating to updating DrawText on a Canvas. I input the text in an EditText box and this displays fine on the canvas using DrawText. However, if I want to delete some text then I want the text on the canvas to recognise when the backspace key has been pressed so that it deletes the characters/text on DrawText on the canvas. I've done some searching on the forums but can't find anything to point me in the right direction. I've tried various methods but just can't get it to work. Thanks in advance.
Hi Guys, I'm a relative newbie here but I have a question relating to updating DrawText on a Canvas. I input the text in an EditText box and this displays fine on the canvas using DrawText. However, if I want to delete some text then I want the text on the canvas to recognise when the backspace key has been pressed so that it deletes the characters/text on DrawText on the canvas. I've done some searching on the forums but can't find anything to point me in the right direction. I've tried various methods but just can't get it to work. Thanks in advance.
stevel05 Expert Licensed User Longtime User Jan 17, 2012 #2 Have a look at this thread, there are a few options there. Upvote 0
A artiechappie Member Licensed User Longtime User Jan 17, 2012 #4 Hi Guys, Thanks for the pointers but the only KeyCode I could find was KEYCODES_BACK which references the Android back key and not the keyboard Backspace key which is what I was looking for. This: Sub Activity_KeyPress (KeyCode As Int) As Boolean If KeyCode = KeyCodes.KEYCODE_BACK Then Msgbox("Backspace key pressed (not)","Result") End If End Sub ... brings up the MsgBox only when I press the back key. Any tips? Thanks Upvote 0
Hi Guys, Thanks for the pointers but the only KeyCode I could find was KEYCODES_BACK which references the Android back key and not the keyboard Backspace key which is what I was looking for. This: Sub Activity_KeyPress (KeyCode As Int) As Boolean If KeyCode = KeyCodes.KEYCODE_BACK Then Msgbox("Backspace key pressed (not)","Result") End If End Sub ... brings up the MsgBox only when I press the back key. Any tips? Thanks
stevel05 Expert Licensed User Longtime User Jan 17, 2012 #5 Try logging the keycode (Log("KeyCode "&Keycode)) received in Activity_KeyPress when you press the backspace key and see what you get. Upvote 0
Try logging the keycode (Log("KeyCode "&Keycode)) received in Activity_KeyPress when you press the backspace key and see what you get.
A artiechappie Member Licensed User Longtime User Jan 17, 2012 #6 Thanks Steve05 Good tip Put this in: Code: Copy Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the eventKey Log("KeyCode Pressed = "&KeyCode) End Sub ... and got this in the log: KeyCode Pressed = 4 so tried the process again with: If KeyCode = KeyCodes.KEYCODE_4 Then Msgbox("Backspace key pressed (not)","Result") End If Still no joy. Thanks for any help you can offer Last edited by a moderator: Jan 17, 2012 Upvote 0
Thanks Steve05 Good tip Put this in: Code: Copy Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the eventKey Log("KeyCode Pressed = "&KeyCode) End Sub ... and got this in the log: KeyCode Pressed = 4 so tried the process again with: If KeyCode = KeyCodes.KEYCODE_4 Then Msgbox("Backspace key pressed (not)","Result") End If Still no joy. Thanks for any help you can offer
Erel B4X founder Staff member Licensed User Longtime User Jan 17, 2012 #7 4 is the actual value. It should be: Code: Copy If KeyCode = 4 Then Upvote 0
A artiechappie Member Licensed User Longtime User Jan 17, 2012 #8 Duh..... Sorry guys, Just realised that I was getting "Keycode Pressed = 4" in the log because I was actually pressing the "Back" key to exit the application. Anyone know what the keycode is for the backspace key? Upvote 0
Duh..... Sorry guys, Just realised that I was getting "Keycode Pressed = 4" in the log because I was actually pressing the "Back" key to exit the application. Anyone know what the keycode is for the backspace key?
A artiechappie Member Licensed User Longtime User Jan 17, 2012 #9 .... all I want to do is update the text on the Canvas if the backspace key is pressed to correct an entry - maybe there's another way of doing this? Upvote 0
.... all I want to do is update the text on the Canvas if the backspace key is pressed to correct an entry - maybe there's another way of doing this?
stevel05 Expert Licensed User Longtime User Jan 17, 2012 #10 Not all keys generate a keycode, I don't think that the backspace key is a 'standard' android key, It certainly doesn't appear on my phone. It may be supported on the newer tablet versions Android 3+ possibly. You could designate a different key, or add a button to your layout. Upvote 0
Not all keys generate a keycode, I don't think that the backspace key is a 'standard' android key, It certainly doesn't appear on my phone. It may be supported on the newer tablet versions Android 3+ possibly. You could designate a different key, or add a button to your layout.
JonPM Well-Known Member Licensed User Longtime User Jan 17, 2012 #11 Maybe post your project file Sent from my DROIDX Upvote 0
A artiechappie Member Licensed User Longtime User Jan 20, 2012 #12 JonPM said: Maybe post your project file Sent from my DROIDX Click to expand... Here's my code snippet as a Canvas test. What I want to do is make the text that appears on the canvas editable - for example, if the user presses the backspace key on the Android phone's keyboard then this is reflected on the text that appears on the canvas. I want to be able to create signs, nameplates etc on the canvas area and then save the canvas as a graphic which can be sent to the manufacturer. Thanks for any help. Allen Attachments CanvasTest.zip CanvasTest.zip 6.9 KB · Views: 420 Upvote 0
JonPM said: Maybe post your project file Sent from my DROIDX Click to expand... Here's my code snippet as a Canvas test. What I want to do is make the text that appears on the canvas editable - for example, if the user presses the backspace key on the Android phone's keyboard then this is reflected on the text that appears on the canvas. I want to be able to create signs, nameplates etc on the canvas area and then save the canvas as a graphic which can be sent to the manufacturer. Thanks for any help. Allen
klaus Expert Licensed User Longtime User Jan 20, 2012 #13 Here you are: Code: Copy Sub TextBox1_TextChanged (Old As String, New As String) c.DrawBitmap(B, Null, brect) c.DrawText(New,25,35,tf.CreateNew(Typeface.SERIF, Typeface.STYLE_BOLD), 20, Colors.Black, "LEFT") i.Invalidate End Sub You need to redraw the background bitmap and then draw the text. Best regards. Upvote 0
Here you are: Code: Copy Sub TextBox1_TextChanged (Old As String, New As String) c.DrawBitmap(B, Null, brect) c.DrawText(New,25,35,tf.CreateNew(Typeface.SERIF, Typeface.STYLE_BOLD), 20, Colors.Black, "LEFT") i.Invalidate End Sub You need to redraw the background bitmap and then draw the text. Best regards.
A artiechappie Member Licensed User Longtime User Jan 20, 2012 #14 Great - thanks Klaus. I'll give this a try. Upvote 0
A artiechappie Member Licensed User Longtime User Jan 20, 2012 #15 That worked a treat Klaus - I have a new problem now but I'll create a new thread for that - thanks again!! Upvote 0
That worked a treat Klaus - I have a new problem now but I'll create a new thread for that - thanks again!!