I have a text view name total I want to add a $ symbol in-front so that when i key in a number in the textview, it will appear as currency, Eg.$20 instead of 20

but at other part of my code later, i will also need to get value from this textview which need to exclude the $ symbol

please show me the easiest way to do this

Thank you

有帮助吗?

解决方案

You can create an icon for the dollar symbol, and set it as the left drawable:

TextView textView = (TextView) findViewById(R.id.myTxtView);
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon, 0, 0, 0);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top