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

My template page automatically zooms on mobile devices
Unable to take screenshot in Kivy app running on android
getting error while adding spinner to the right of action bar
How to play tapped List Item Song
I'm trying to make a simple salary counting program. But i cant recieve the data from the other class to the main activity
Different Listview divider after last item but before footer
File Cleaning Service
Facebook android Release key has issue
ga_autoActivityTracking= true: exclude specific activities from being reported
Custom ListView Item barely visible
keyboard showing lately when i press edittext and also take time when i press the back button
SensorEvent.timestamp inconsistency
List view with Dynamic Row Item Android
3D rotation - perspective
Parsing Android multi-part HTTP Post request on the server side
how to create custom font in android?

Categories

HOME
kentico
prism
cheerio
obfuscation
sitecore
graphics
xbee
flume
okhttp
endeca
heap
bitnami
event-sourcing
symfony-2.8
dynamic-sql
aws-sdk
feathersjs
vuejs
wolframalpha
asp.net-core-webapi
windows-xp
squashfs
dpdk
react-toolbox
froala
jquery-multiselect
gpio
bioinformatics
cart
linkedhashmap
biztalk-rule-engine
jwplayer6
batching
fiware-cygnus
zoomify
timing
flatmap
odroid
metawidget
comparison-operators
trigonometry
laravel-elixir
softmax
knime
importerror
apache-directory
dynamic-linq
openal
cnc
dotnet-httpclient
wcftestclient
dbcontext
jtree
filenet
android-instrumentation
sandcastle
pocketsphinx-android
vcloud-director-rest-api
grails-plugin
webjars
seek
pacemaker
dotnetnuke-7
uicolor
jquery-jscrollpane
mapinfo
pre-build-event
false-sharing
libvlc
coda
branch-and-bound
alloy-ui
canvg
ms-access-2000
git-ftp
node-serialport
j-security-check
cryptographichashfunction
android-cookiemanager
administration
psr-4
create.js
build-script
verold
grails-plugin-rabbitmq
ios8-extension
windows-embedded-standard
spring-3
http-patch
insert-id
swfobject
curb
boost-msm
vfs
web-farm
listitem
jsr286
promotion-code
entitydatasource
massive
unattended-processing
msr
resharper-6.0
zen
data-mapping
feasibility

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