android


Edit text integer


Android application is not work, application has stopped unfortunately. Where is wrong code?
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText edittext1 = (EditText) findViewById(R.id.editText1);
final Button button1 = (Button) findViewById(R.id.Button01);
final TextView tw = (TextView) findViewById(R.id.textView1);
final int valueint = Integer.parseInt(edittext1.getText().toString());
button1.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
tw.setText(Integer.toString(20*valueint));
}
});
}
Is code true?
int valueint = Integer.parseInt(edittext1.getText().toString());
You are trying to use empty int value on create. It can work with some numbers in EditText, but when empty it must crash. Also tw.setText metod was wrong. Try this code, working:
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity1 extends Activity {
EditText edit;// = (EditText) findViewById(R.id.editText1);
Button button;// = (Button) findViewById(R.id.button1);
TextView tw;// = (TextView) findViewById(R.id.textView1);
int valueint;// = Integer.parseInt(edit.getText().toString());
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity1);
edit = (EditText) findViewById(R.id.editText1);
button = (Button) findViewById(R.id.button1);
tw = (TextView) findViewById(R.id.textView1);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
valueint = Integer.parseInt(edit.getText().toString());
tw.setText(String.valueOf(20 * valueint));
}
});
}

Related Links

Android navigating to parent Fragment Activity from within Fragments
How to query rows in between two datetime columns?
App crashes when receiving of message
How to make layout have the same height?
Could we use a library project as a jar file?
ADB shows unknown device
can't find picture on storage android
Android convert audio /voice mail file to text file
Forward Declaraton in Android
Speech Recognition on Unity Game Engine
Connect to Bluetooth with Android
Google Tv Emulator AVD System Image
ActionbarSherlock - the libraries I download don't quite look like the ones in tutorials
Posting on facebook wall using Request
Android google map v2 maven
Alignment of Ads in Scrollview in Android

Categories

HOME
sonarqube
ng-idle
numbers
fftw
appcelerator
javacc
xbee
switch-statement
rds
3d-reconstruction
lanczos
special-characters
discrete-mathematics
openbugs
google-form
pybossa
renjin
zerobrane
cumulocity
docx
azure-powershell
scsi
microsoft-dynamics-nav
dreamweaver
jmp
tosca
google-api-client
xcode-ui-testing
onload
maze
fable-f#
fragment-backstack
livelink
recurring-events
left-join
fstream
laravel-eloquent
android-maps-extensions
carriage-return
jpad
loading
linq-to-objects
tasm
stringtokenizer
dcmtk
android-ibeacon
drupal-theming
rfc3339
facebook-social-plugins
podscms
amq
wpas
android-testing
er-diagram
quicktime
mouseleave
flac
pybrain
baidu
donations
cronexpression
xcode-server
mta
nikeplus-api
udpclient
spreadjs
invoke-sqlcmd
cycle2
state-restoration
toran-proxy
opl
gocql
forwarding
flock
binomial-theorem
lasso
rdflib
liquid-layout
zxspectrum
bcache
dbaccess
metatrader5
punycode
psr-4
universal-image-loader
decoupling
dsym
printdialog
workitem
video-codecs
onload-event
extreme-programming
saleslogix
catransform3d
google-floodlight
jqote
timthumb
msr
twitterizer
undefined-index
easyb
zend-rest
pos-for-.net
blender-2.49
cfwindow
murmurhash
int64

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