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

SupportMapFragment not working , gives error [closed]
CWAC-MediaRouter overwrites my app theme
XMPP MessageEventManager error while send packet?
Selecting Audio Stream in android for music
sharedpreferences remains when the app is closed
Android ActionBar and Bluetooth keyboard
Hiding keyboard - getCurrentFocus() return null
Animate List Item content on long press listView
Android Wifi Settings within app(Kiosk-sh app)
Android TV Leanback imagecardview text color
ListView is not visible
Dialog dismiss on AsyncTask timeout
Glitch On Change Image Drawable While Scrolling. Stuttering Issue.?
Adding image to gallery in Android
How to remove the gap around large icon in notification
Youtube uploading Video Android

Categories

HOME
search
gridview
forms
redux-form
android-studio-2.2
formal-languages
datastore
hessian
nuget
replace
alarm
python-multithreading
jax-ws
trac
performancepoint
fosrestbundle
syntaxnet
augeas
google-chrome-app
text-mining
siddhi
startup
alamofire
jxl
supervisor
comsol
frequency-distribution
symmetricds
altera
android-7.0-nougat
pyramid
cfml
string-concatenation
roundup
licensing
outliers
datastax-enterprise-graph
quantlib
corenlp-server
jmockit
playstation-portable
instantiation
navigator
magento-1.9.2.4
xdocreport
node-mssql
diacritics
news
escpos
linqpad
posixct
trojan
dt
cd-burning
sandcastle
usart
angular2-testing
atlas
rspec2
x-tag
cfchart
nservicebus5
hadoop-partitioning
turbo-prolog
thread-sleep
false-sharing
atan2
microsoft-reporting
poppler
batik
mod-proxy
eoferror
google-refine
nutiteq
aspectj-maven-plugin
node-serialport
kubuntu
procedural-programming
adehabitathr
structuremap3
paw
tinyxml
dct
spring-remoting
vbe
android-audiorecord
ebay-lms
dolby-audio-api
video-codecs
sentestingkit
web-farm
xcode3.2
paginator
cgimage
node-redis
entity-attribute-value
promotion-code
u2netdk
unattended-processing
cloudfiles
svk
photolibrary
easyb
aspmenu
zend-rest
nstokenfield
pagemethods
strtod
cuda.net
fail-fast-fail-early

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