android


periods not available in keypad to enter in edittext in android


I have a EditText, where I need to enter price. I need to show $ symbol before the digits and two decimal after period(.55) and period should be once. I used the following code. But when I hit "." it doesn't appear in the EditText.
<EditText
android:id="#+id/editTextForAddItemPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginBottom="20dp"
android:inputType="numberDecimal"
android:digits="0123456789.,$"
android:layout_marginTop="20dp"
android:layout_toRightOf="#+id/textForAddItemPrice"
android:background="#color/app_bg_color"
android:gravity="right"
android:textColor="#color/txt_color_gray"
android:textSize="17dp" />
editTxtForPrice.addTextChangedListener(new TextWatcher() {
boolean isEdiging;
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
// String sText = editTxtForPrice.getText().toString();
if(s.length()>0)
{
if(isEdiging) return;
isEdiging = true;
String str = s.toString().replaceAll( "[^\\d]", "" );
if(!str.equals(""))
{
double s1 = Double.parseDouble(str);
NumberFormat nf2 = NumberFormat.getInstance(Locale.ENGLISH);
((DecimalFormat)nf2).applyPattern("$ ###,###.###");
s.replace(0, s.length(), nf2.format(s1));
}
isEdiging = false;
}
}
});
I used a textwatcher, which solved my problem.
editTxtForPrice.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
if (!s.toString().equals(current)) {
editTxtForPrice.removeTextChangedListener(this);
String cleanString = s.toString().replaceAll("[$,.]", "");
double parsed = Double.parseDouble(cleanString);
String formatted = NumberFormat.getCurrencyInstance()
.format((parsed / 100));
current = formatted;
editTxtForPrice.setText(formatted);
editTxtForPrice.setSelection(formatted.length());
editTxtForPrice.addTextChangedListener(this);
}
}

Related Links

Eclipse - Emulator - eglSurfaceAttrib not implemented
Can Android drawable's clip-path layer be rotated?
Reading multiple textfile (.txt) from Asset / Raw Folder
Android: onSharedPreferenceChanged does not change a summary of PreferenceScreen
Email Composer Plugin is not working on Android 6 (Marsh Mallow) with cordova
CheckBox checked in OnBindViewHolder isn't checked when displayed
Android Firebaseui is not retrieving all data
Displaying Database on Listview
Android 4.0.3 API15 doesn't show in AVD manager
Telegram Api usage understading
Come back from FragmentPagerAdapter
Unit testing a network response. Works when debugging, not when actually running
Android music player saving song id and now playing list
Set MenuItem text Center Align in Navigation View in Android
How to get file path , When uploading a file to server?
Two Application's using sharedUserID - createPackageContext issue

Categories

HOME
android
uml
go
search
kentico
api
paraview
awk
rdbms
powerpoint
rsa
youtube-data-api-v3
solver
gradient
spring-data-mongodb
simulink
hpc
zip
banner
flume
reactive-programming
redis-sentinel
docx
intershop
google-container-registry
dpdk
short-url
outliers
cppreference
send
dumpbin
wacom
login-script
nested-lists
getlasterror
fiware-cygnus
alphabetical
google-earth-engine
urlsession
claims
oracle-service-bus
outputcache
angular-http
android-exoplayer
show-hide
stylecop
strftime
phpdbg
fwrite
dotnet-httpclient
globalize
bluez
magic-draw
video-conferencing
google-photos
juice-ui
cronexpression
node-request
cudd
pure-css
centrifuge
macaulay2
beamer
jboss-tools
expectations
observablecollection
refinerycms
android-wake-lock
tracker-enabled-dbcontext
cortex-m
libvlc
directdraw
concurrentmodification
vigenere
visual-sourcesafe-2005
mod-proxy
graphics2d
telepat
jquery-forms-plugin
xmltype
public-html
cross-join
theos
webmatrix-3
angular-gettext
sip-server
contrast
cocos3d
reflector
live555
functional-java
draw2d-js
websphere-esb
modular
merb
node-blade
dolby-audio-api
superscrollorama
apache-abdera
sqlclr
monotouch.dialog
veracity
pyunit
listitem
failing-tests
flex-mobile
xcelsius
xui
rowlex
burndowncharts
strtod
skype4java
fdf
great-circle

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App