B
B
Brenly2020-01-31 08:55:47
Java
Brenly, 2020-01-31 08:55:47

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

2 answer(s)
S
Sashulya, 2020-01-31
@Shikato

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

B
Brenli, 2020-02-01
@Brenli

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. ?

Similar questions
K
KhanTengri2011-06-17 23:56:41
Get from a remote web page?</a> <a class="content__item-button" href="/q/get-title-from-a-remote-web-page"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" class=""> <path fill-rule="evenodd" d="M15 14a1.002 1.002 0 01-1.703.71h-.004l-.003-.01-1.704-1.7H3c-1.104 0-2-.9-2-2V3c0-1.1.896-2 2-2h10c1.104 0 2 .9 2 2v11zM5 6c.552 0 1 .45 1 1s-.448 1-1 1-1-.45-1-1 .448-1 1-1zm3 0c.552 0 1 .45 1 1s-.448 1-1 1-1-.45-1-1 .448-1 1-1zm3 0c.552 0 1 .45 1 1s-.448 1-1 1-1-.45-1-1 .448-1 1-1z"></path> </svg> <span class="dark">6</span><span class="dn">Reply</span> </a> </div> </div><div class="content__item"> <div class="content__item-img name-color-L"> <span>L</span></div> <div class="content__item-content"> <div class="content__item-row"> <a href="/q/why-does-this-error-occur-and-how-to-add-beans-to-the-project">LinuxGod</a><span>2020-04-24 18:37:09</span></div> <a class="content__item-title similar" href="/q/why-does-this-error-occur-and-how-to-add-beans-to-the-project">Why does this error occur and how to add beans to the project?</a> <a class="content__item-button" href="/q/why-does-this-error-occur-and-how-to-add-beans-to-the-project"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" class=""> <path fill-rule="evenodd" d="M15 14a1.002 1.002 0 01-1.703.71h-.004l-.003-.01-1.704-1.7H3c-1.104 0-2-.9-2-2V3c0-1.1.896-2 2-2h10c1.104 0 2 .9 2 2v11zM5 6c.552 0 1 .45 1 1s-.448 1-1 1-1-.45-1-1 .448-1 1-1zm3 0c.552 0 1 .45 1 1s-.448 1-1 1-1-.45-1-1 .448-1 1-1zm3 0c.552 0 1 .45 1 1s-.448 1-1 1-1-.45-1-1 .448-1 1-1z"></path> </svg> <span class="dark">0</span><span class="dn">Reply</span> </a> </div> </div><div class="content__item"> <div class="content__item-img name-color-C"> <span>C</span></div> <div class="content__item-content"> <div class="content__item-row"> <a href="/q/how-to-make-a-simple-web-application-for-a-psychological-test">Comatu</a><span>2018-02-18 16:59:43</span></div> <a class="content__item-title similar" href="/q/how-to-make-a-simple-web-application-for-a-psychological-test">How to make a simple web application for a psychological test?</a> <a class="content__item-button" href="/q/how-to-make-a-simple-web-application-for-a-psychological-test"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" class=""> <path fill-rule="evenodd" d="M15 14a1.002 1.002 0 01-1.703.71h-.004l-.003-.01-1.704-1.7H3c-1.104 0-2-.9-2-2V3c0-1.1.896-2 2-2h10c1.104 0 2 .9 2 2v11zM5 6c.552 0 1 .45 1 1s-.448 1-1 1-1-.45-1-1 .448-1 1-1zm3 0c.552 0 1 .45 1 1s-.448 1-1 1-1-.45-1-1 .448-1 1-1zm3 0c.552 0 1 .45 1 1s-.448 1-1 1-1-.45-1-1 .448-1 1-1z"></path> </svg> <span class="dark">3</span><span class="dn">Reply</span> </a> </div> </div> </div> </div> </div> <div class="content find"> <p class="find__p">Didn't find what you were looking for?</p><a class="find__btn" href="#!">Ask your question</a> </div> <div class="find sm"> <p class="find__title">Ask a Question </p> <form class="find__form" action="#!"> <input class="find__input" type="text" placeholder="Ask your question here"> <button class="find__btn" type="submit"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 16 16" class="nBqR1"><path fill-rule="evenodd" d="M12.696 7.256L9.657 4.217a1 1 0 00-1.415 1.414l1.344 1.344H3.949a1.001 1.001 0 000 2h5.637l-1.344 1.343a1.002 1.002 0 000 1.415c.391.39 1.024.39 1.415 0l3.039-3.04A.993.993 0 0013 7.975a.997.997 0 00-.293-.708l-.011-.011z"></path></svg></button> </form> <p class="find__span">731 491 924 answers to any question</p> </div> </div> <aside class="banners"> <p>banners </p> </aside> </div> </main> </div> <script src="/assets/theme/js/highlight/highlight.min.js"></script> <script src="/assets/theme/js/app.min.js?_v=20220404145216"> </script> <script>hljs.highlightAll();</script> </body> </html>