Last active
June 12, 2019 12:08
Star
You must be signed in to star a gist
RupeeTextView . Which Prefixes ₹ symbol and adds commas separated amount value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.util.AttributeSet; | |
import android.widget.TextView; | |
import com.billion.grow.logger.Log; | |
import java.text.DecimalFormat; | |
import java.text.NumberFormat; | |
import java.util.Locale; | |
/** | |
* Created by john on 7/7/16. | |
*/ | |
public class RupeeTextView extends TextView { | |
Context context; | |
public RupeeTextView(Context context) { | |
super(context); | |
this.context = context; | |
} | |
public RupeeTextView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
this.context = context; | |
} | |
public RupeeTextView(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
this.context = context; | |
} | |
@Override | |
public void setText(CharSequence text, BufferType type) { | |
String formatedString = null; | |
try { | |
// The comma in the format specifier does the trick | |
DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.US); | |
formatter.applyPattern("#,##,##,##,###"); | |
formatedString = String.format("₹" + formatter.format(Double.parseDouble(text.toString()))); // adds rupee symbol and thousand seperater | |
} catch (NumberFormatException e) { | |
Log.d("Rupee TextView NumberFormatException"); | |
e.printStackTrace(); | |
} | |
super.setText(formatedString, type); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. Still works in API 27.