android


How to multiply two EditTexts?


okay i got this code it works perfectly with all normal numbers but when i run it and give the First or second EditText (0.1, 0.2 , 0.3 , 0.4) or any other numbers start with (0. ) it gets an error so please help me out!
public class Main extends Activity {
EditText num1,num2;
TextView resu;
int res;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button add=(Button) findViewById(R.id.add);
num1=(EditText) findViewById(R.id.etnum1);
num2=(EditText) findViewById(R.id.etnum2);
resu=(TextView) findViewById(R.id.textView4);
add.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String mynum1=num1.getText().toString();
int mnum1=Integer.parseInt(mynum1);
String mynum2=num2.getText().toString();
int mnum2=Integer.parseInt(mynum2);
res=mnum1*mnum2;
resu.setText(Integer.toString(res));
}
});
}
}
You need to convert your EditTextvalues to Float like:
String mynum1=num1.getText().toString();
float mnum1= Float.parseFloat(mynum1);
String mynum2=num2.getText().toString();
float mnum2= Float.parseFloat(mynum2);
float res=mnum1*mnum2;
resu.setText(String.valueOf(res));
Hope this may help you!
EditText num1,num2;
TextView resu;
double res;
in your onClickview()
double mnum1=Double.parseDouble(mynum1);
String mynum2=num2.getText().toString();
double mnum2=Double.parseDouble(mynum2);
res=mnum1*mnum2;
resu.setText(Double.toString(res));

Related Links

Where should async task be executed in fragment to update the view?
How to hide FAB is show in Android
Webservice call on current displayed fragment viewpager?
Animating custom view(leaf node in ViewHierarchy ) using ObjectAnimator is not smooth in android
Android Realm repalce refresh with waitForChange
Create Marker with lat and long from JSON file inside Assets folder
Android - how to check if ThreadPoolExecutor has reached the queue limit?
Failed to load resource: net::ERR_FILE_NOT_FOUND ionic error
Google Play Store not always shows current app version
Revert to MainActivity after pausing/exiting on SecondActivity
location.reload() causing cordova sqlite db to be locked
how to add android drm plugin
Last Accessed Time of any file in Android
Is it possible to make android library contains readme.txt?
Accelerometer RxJava Backpressure
ionic run android not work

Categories

HOME
grok
gridview
cobalt
developer-tools
fftw
solaris
owl-carousel
javacc
parameters
visual-studio-emulator
pyqt4
maxscript
trac
character
redis-sentinel
speech-synthesis
3nf
cumulocity
searchview
null-pointer
digital-signature
googlebot
ksh
springfox
roslyn
joptionpane
mount
google-cloud-print
fat
android-sharedpreferences
handler
getpixel
hunspell
latitude-longitude
parse-tree
odroid
signals-slots
resolution
levenshtein-distance
portforwarding
lpsolve
file-sharing
show-hide
clang++
openresty
datamaps
podscms
semantic-logging
dt
janus
objectscript
ampps
structuremap4
chromium-os
async.js
watch-os-2
model-associations
synonym
cifilter
gogs
ikiwiki
crouton-os
terracotta
wiredep
vigenere
pax-exam
amiga
jsvc
google-refine
openbabel
entry-point
trdion2011
named-parameters
rcaller
kendo-dataviz
inputmismatchexception
observium
chart-director
device-width
faye
listitem
cross-database
stress
apache-commons-dbutils
luabind
gobject-introspection
matlab-load
creole
load-time
cruisecontrol.rb
globals
non-clustered-index
office-2007
openfaces
django-piston
echo3
business-model

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