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

set Hindi as TextToSpeech language in android programatically
How to make a link redirecting on Apple store or Google play
How to rotate image slowly in android?
Find element by class-name and content-desc in web context selenium
Retrofit - Failure in SSL library, usually a protocol error
Redirect site page on Intel XDK
How to implement own cast.receiver.media.Player
Titanium View.toImage() and base64 encode not always decoding properly
How does Firebase crash reporting initialize
AVD errors with HAX on Android Studio 2.1
Slider and ngModel lagging with finger slide
How to set proper version control for Ionic project
Android Studio Gradle task stuck
Android file access questions
GLSL 2.0 Shader giving different light in different device
Find the default value of javaMaxHeapSize in Android

Categories

HOME
algorithm
asp.net-web-api
api
ng-idle
ggplot2
ns-3
grafana
database-normalization
dojo
ado.net
spring-session
special-characters
elasticsearch-5
pattern-matching
octave
reactive-programming
shared-libraries
azure-powershell
atlassian-stash
fileserver
digital-signature
cfml
swagger-2.0
apache2.4
lilypond
breadth-first-search
libigl
joptionpane
qliksense
definitelytyped
opentk
shared
ms-access-2003
paperjs
mql
ntp
indy10
jwplayer6
sharepoint-workflow
bc
print-css
claims
http-request
stylecop
facebook-pixel
configurationmanager
x-ray
page-replacement
payara-micro
arq
lsyncd
sandcastle
gets
rocks
autosar
custom-lists
redbeard-ios
pacemaker
macaulay2
mta
vorpal.js
nupic
nio2
grass
linklabel
decimalformat
tfs-workitem
sciruby
xenomai
forwarding
page.js
branch-and-bound
linked-tables
mruby
spy++
paw
winginx
ray
amslidemenu
mt4j
cmmi
nevron
font-awesome-4.0.0
server-administration
booksleeve
pyunit
role
appledoc
collectionviewsource
svk
undefined-index
maven-1
folding
tabpanel
pagemethods
spread
build-environment
wysiwym
fault-tolerance

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