Android Question Add "$" Symbol to Edittext

German Buchmuller

Member
Licensed User
Longtime User
Hi, I want to add the Currency symbol to the begining of the editext, so that when the user writes a number, automatically the symbol "$" will be added to the begining of the editext. Thanks to all
 
Code: Copy
Dim CurrencySymbol As String
CurrencySymbol = "$"
=
Code: Copy
Dim CurrencySymbol As String = "$"

Modifying the text while the user changes it can result in a bad UX. For example if the user adds a character before the $ sign then it will add a new $ sign. I think that you will get better result if you add it when the focus is removed.
 
Upvote 0
Dim CurrencySymbol As String = "$"
:eek: Is it possible?

Just to emphasize the fact that it is a variable and that will be set based on localization.
I prefer to use your "kind of statement" for constants.

;)


Modifying the text while the user changes it can result in a bad UX. For example if the user adds a character before the $ sign then it will add a new $ sign. I think that you will get better result if you add it when the focus is removed.
I agree (of course :D)
 
Upvote 0
Thanks to both!! It worked. Now, how can I do so that I can do math calculation with this values? As it has the currency symbol before, It shows no result after the "calculate" button is pressed. Its a bit difficult to understand, guess you could. Thanks again!
 
Upvote 0
You could add an image to the edittext that will always be there and not interfere with the editing. You could of course get the currency symbol based on the locale as well if needed)

Code: Copy
Sub EditTextSetup(EditTxt As EditText)
    
    'Create a bitmap to draw on
    Dim BMP As Bitmap
    BMP.InitializeMutable(40dip,40dip)
    
    'Create a Canvas and assign to the bitmap
    Dim C As Canvas
    C.Initialize2(BMP)
    C.DrawText("$",20,40,Typeface.DEFAULT,20,Colors.White,"CENTER")
    
    'Convert the bitmap to a Drawable
    Dim BMD As BitmapDrawable
    BMD.Initialize(C.Bitmap)
    
    'Add the image to the edit text
    Dim ETxt As JavaObject = EditTxt
    ETxt.RunMethod("setCompoundDrawablesWithIntrinsicBounds",Array As Object(BMD,Null,Null,Null))
End Sub
 
Upvote 0
Back
Top