android


One method for several buttons?


Instead of have to call separate method for each button, would it be possible to just use one method and check which button it was that was clicked by it's id?
I'm using the simple way like android:onClick="activateButtons"
public void activateButtons(View v)
{
if(?? == btn_1)
{
Code for button with ID = btn_1
}
if(?? == btn_1)
{
Code for button with ID = btn_2
}
}
You can do that if you tag the buttons with an Id. Set the android:id="#+id/yourbuttonid" in the xml file. Then do if(v.getId() == R.id.yourbuttonid) in the onClick method.
Yes it is possible. You can assign specific ids(eg: button1) for buttons and then call v.getId() in activateButtons(onclick method) to check if it is equal to R.id.button1 and then do your operation there.
Cheers,
Richie
public void onClickKeyPad(View view)
{
EditText text = (EditText)findViewById(R.id.text_password);
switch(view.getId())
{
case R.id.button_0:
text.setText(text.getText() + "0");
break;
case R.id.button_1:
text.setText(text.getText() + "1");
break;
case R.id.button_cancel:
finish();
break;
default:
break;
}
}

Related Links

Upgrade Kotlin from 1.0.2 - 1.0.3: java.lang.NoSuchMethodError: No virtual method provideInjectedData$app_compileDebugKotlin()
Multiple Activities in Android manifest/app drawer [duplicate]
How do I pass data back to an activity that starts the activity which passes data to it?
How specify sign in button scopes in xml?
How to use PercentRelativeLayout in a CollapsingToolbarLayout?
could not find wglGetExtensionsStringARB
ImageView not updated after device is switched off an on again, while app is on top
onScrolled RecyclerView not triggered after DataSet changes
Open global search as overlay
take the activity content to dialog
Xamarin Android SDK Location
Android - Restoring App Widgets on Reboot or Crash
Android global scope String returns null
What is Virtual Reality View(vr view) in android? [closed]
Run GcmListenerService New Process
xamarin NavigationView gives error no resource found for app:headerLayout

Categories

HOME
azure-stream-analytics
google-cloud-platform
cobalt
polymer
wakanda
mjml
mysql-workbench
interface
battery
access
ado.net
lanczos
extjs4.2
spin
octave
mxgraph
ycsb
xcodebuild
rtf
selenium-ide
frequency-distribution
flatpak
heat
modbus-tcp
glyphicons
esoteric-languages
asp.net-mvc-viewmodel
pyramid
jmp
delphi-xe5
sencha-touch
solrcloud
roslyn
moses
fragment-backstack
has-and-belongs-to-many
rpgle
comparable
panoramas
zend-debugger
quickfixj
carriage-return
browser-extension
openproject
metaprogramming
parser-generator
naming
linqpad
tcc
dapper-simplecrud
ntvs
rserve
stdmap
trigger.io
gameplay-kit
rxtx
android-instrumentation
vcloud-director-rest-api
smartfoxserver
mapxtreme
mapinfo
avspeechsynthesizer
refinerycms
embedding
cassia
redis-cluster
html-to-pdf
database-relations
nio2
piracy-prevention
jnlua
maybe
toran-proxy
iokit
rdflib
typeconverter
zend-currency
umlgraph
exceldatareader
sql-scripts
device-tree
insight.database
personalization
file-not-found
git-repo
windows-embedded-standard
gd-graph
away3d
cocoalibspotify-2.0
script#
mvc-editor-templates
cnf
facebook-timeline
abstract-data-type
dolby-audio-api
diem
superscrollorama
booksleeve
onmousemove
uimanageddocument
garbage
jsr286
luabind
google-floodlight
cgbitmapcontextcreate
aspmenu
murmurhash
web-application-project
cldc
blind

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