android


Arrangement views in Layout


I'm sorry for this question but i'm confused about it.
I have two buttons like this:
<Button
android:id="#+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />
<Button
android:id="#+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
And in the Android code :
a = (Button) findViewById(R.id.b1);
b = (Button) findViewById(R.id.b2);
a.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//my code
}
});
When I change the arrangement of the buttons to look like this:
<Button
android:id="#+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
<Button
android:id="#+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />
then the a button doesn't listen. The listener is associated to the b button!
You might have changed the ids while rearranging.
<Button
android:id="#+id/b2"
/>
<Button
android:id="#+id/b1"
/>
Check that, and clean + build project. Hope it helps.
When you rearrange the buttons the listener will move to the second button,
So when you will click the button with text = 2 you wouldn't get anything,
and when you click the button with text = 1 you will have the action assigned.
Otherwise in the fist case, the 2 button will respond and not the 1

Related Links

Android LocationServices lastKnownPosition
Reuse RxJava stream from a remote API
Listening for tweet with Android app
App comparison using androguard
shadows are showing in unity editor but not on android device
hudson2 project android build turn indefinitely
SimpleCursorAdapter deprecated, what to do now? [duplicate]
Creating launcher like drag and drop with multiple screens in android
how to show the list of filenames in listview from SDcard in android?
Is Sqlite database persistent for android system apps on Device Wipe / Factory Reset
Android Accessibility - Edit all touch events
Unable to fetch all the contacts from Android
import fizzbuzz not found
Change fragment and navigation drawer state from fragment class
Jsoup HTML parsing and display with multiple views in Android
Variable is accessed from within inner class , needs to be declared final

Categories

HOME
windows
scikit-learn
wakanda
css3
google-spreadsheet
mysql-workbench
themes
apache-spark-mllib
devise
error-handling
gradient
nuget
switch-statement
cq5
tail
gembox-spreadsheet
limit
ado.net
settings
android-json
banner
sendgrid-api-v3
redis-sentinel
xcodebuild
rtf
nancy
intercom
jersey-1.0
oledb
breadth-first-search
springfox
libigl
pagespeed
mongoid6
froala
definitelytyped
fable-f#
exchangewebservices
subclass
gitlab-api
login-script
gnat-gps
searchkit
reason
password-protection
metaprogramming
tasm
escpos
android-ibeacon
lpsolve
android-exoplayer
getchar
clarifai
serde
mschart
trojan
jqchart
filenet
taocp
seek
delta
eigenvector
clipboard.js
mediametadataretriever
spreadjs
createprocess
design-principles
libvlc
custom-errors
rate-limiting
intel-c++
phonertc
toolkit
fail2ban
mmwormhole
infosphere-spl
rapidsvn
boost-program-options
sip-server
ss7
fpdi
decoupling
windows-embedded-standard
gwt-openlayers
gtm-oauth2
scrypt
cocoalibspotify-2.0
hidapi
pagedown
windows-98
cardreader
dopostback
os.system
faye
objectquery
thttpd
screen-size
google-floodlight
timertask
eclipse-marketplace
web-garden
spread
lalr
todos
localizable.strings
firefox-3

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