android


How do you make a button return a boolean value?


I am trying to make a stop watch application that when you press start it starts and when you press stop it stops. I am using a handler and runnable with post delay, but I want it to only post if the Stop button has not been pressed. This is the way I am talking about implementing what I am talking about.
if(!StopBClicked()){
handler.postDelayed(r, 1000);
}
This is what I have so far for making it a boolean thing.
public boolean StopBClicked() {
Button StopB = (Button)findViewById(R.id.StopB);
StopB.setOnClickListener(new View.OnClickListener(){
return true;
}
}
But as you might guess it doesn't work. It is giving me an error at the ")" after OnClickListener(. I am a little new so I would appreciate a example code. Thank you.
Just run your action when the button is clicked.
Add this to your onCreate:
Button StopB = (Button)findViewById(R.id.StopB);
StopB.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
handler.postDelayed(r, 1000);
}
}
Haven't done any Android dev, but I would presume it's a syntax error. Assuming it's not a copy error made by the StackOverflow editor pasting some code, shouldn't it be:
private boolean StopBClicked() {
Button StopB = (Button)findViewById(R.id.StopB);
StopB.setOnClickListener(new View.OnClickListener(){
return true;
});
}

Related Links

Sromku facebook login issue
Set app activity to accept action.VIEW action
Send AT+COPS command to android phone
Android L CardView horizontal
“this app won\'t work unless you update google play services” error
How does mobile application find users nearby
Cross platfrom menu with Cordova
Menu not refreshing on some devices
How to Show Device's Home Launcher from my own Launcher
Android BroadcastReceiver doesn't always work
Proguard ParseException: “Expecting keyword 'allowshrinking', 'allowoptimization', or 'allowobfuscation' before 'includedescriptorclasses”' on -Keep
How to embed vrml animation on android html application
Converting drawable resource to Bitmap Android
Fragment Transaction show() does not show fragment on second time
Viewport setting ignored in Phonegap Android app, but only on certain phones?
How to send data from android application to client's database?

Categories

HOME
service-worker
batch-file
cygwin
grok
google-cloud-platform
fpga
github-for-windows
vxml
square
interpolation
code-coverage
discrete-mathematics
g++
minecraft-forge
endeca
siddhi
mxgraph
filechannel
naivebayes
google-form
do-while
mvc-mini-profiler
googlebot
poedit
easeljs
syntax-highlighting
licensing
apktool
android-things
subclass
errbot
complex-numbers
mockjax
playstation-portable
laravel-eloquent
hreflang
android-gridview
classcastexception
keras-layer
sharding
python-pptx
swagger-php
openerp-7
sim-card
metaprogramming
google-data-api
urlsession
smoothstate.js
file-sharing
plan-9
geotiff
openblas
static-cast
azure-cli
jqchart
lsyncd
gets
cronexpression
tinkerpop3
uicolor
xdoclet
appscale
kango-framework
bizagi
halcon
contentcontrol
tfs-workitem
computer-architecture
poppler
text-search
coda
canalyzer
branch-and-bound
apache-commons-daemon
nutiteq
iiop
punycode
human-computer-interface
mdichild
create.js
cuba
lnk
functional-java
android-framework
terminate
extjs2
ecslidingviewcontroller
notorm
mongohq
epiceditor
fragmenttransaction
zope.interface
window-decoration
koken
google-maps-mobile
android-holo-everywhere
lr
creole
massive
unattended-processing
diagrams
delimited-text
blender-2.49
request-headers
spread
sqlobject
technical-debt

Resources

Encrypt Message