Answer the question
In order to leave comments, you need to log in
How to implement permanent display of currency icon in EditText?
Hello.
I am doing a practical task of the course, I am designing the interface, there are 2 text fields name and price of the EditText type, the price has a currency icon in the hint property, but it is hidden when entering values - how to make it so that currencies are always displayed?
Is there a way to make the hint show up all the time? Or just add a currency symbol through concatenation?
Answer the question
In order to leave comments, you need to log in
Option 1 - in the code make sure that the new text is added with the currency icon (concatenation) - it seems to me the most reasonable solution
Option 2 - make the currency icon a separate TextView and remove the hint
I use price.setText(" ₽"); in the OnCreate method everything rolls, but there are 2 points:
1) the field has an inputType of type number
2) A symbol is added to the hint - "0 ₽"
If you put 0 in price.setText(" ₽"), then 0 is constantly on and the color black - different from hint .
I'm trying to make such a condition in the method of the TextWatcher object
public void afterTextChanged(Editable s) {
if (!TextUtils.isEmpty(price.getText())){
price.setText(" ₽");
}
}
The application hangs on execution when trying to change the value of a field. Probably because it's worth type number, but why doesn't it hang in the open setText() method, but does it in the TextWatcher object method?
How can I implement my logic - when there is nothing in the field, hint is displayed in a pale color and with 0, as soon as at least one digit is entered, a currency sign is put. ?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question