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 Studio: App keeps crashing on start
Create RecyclerView IN FRAGMENT
PhoneGap “not found” page, close using back button
cannot find symbol class android.net.ConnectivityManager.NetworkCallback
How to make a circular Button?
How do I run Node.js api after certain interval of time?
How can I get the values out of onDataChange method?
Play a video when clicking a button
I am facing this message during run the program
Firebase public Task <T> addOnCompleteListener() method
How do I make a call to PHP api to check for new notifications in Ionic and display notification?
How can i use DeepLink in android
Custom ads in AdMob
android studio error after update :app:mergeDebugResources FAILED
How to focus accessibility event on a particular data item in RecyclerView
Why is this xml layout starting centre then jumping to the bottom after a second?

Categories

HOME
prism
codenvy
merge
ecmascript-6
apache-spark-mllib
serialization
hessian
can
cq5
pyqt4
mvc5
lanczos
fabric.io
g++
dkim
emoji
aws-sdk
template-engine
foreign-keys
swagger-2.0
google-maps-autocomplete
blade
gulp-watch
shared
has-and-belongs-to-many
soot
errbot
userdefaults
scatter3d
fstream
activexobject
playframework-2.1
cd
modernizr
node-mssql
ods
metaprogramming
levenshtein-distance
sharp-snmp
claims
android-exoplayer
apache-directory
dapper-simplecrud
servermanager
mesosphere
nanoc
fclose
dbcontext
amq
qtranslate
subnet
edit
jqchart
lsyncd
shinobi
swingworker
sandcastle
reachability
chromium-os
autosar
lua-telegram-bot
tracker-enabled-dbcontext
blitline
character-replacement
rubaxa-sortable
atoi
botan
android-broadcast
fits
xmltype
public-html
document-repository
ejb-2.x
iiop
ignite-ui
square-bracket
openargs
code-duplication
scmmanager
booksleeve
tree-balancing
boost-msm
mapping-by-code
oracle-enterprise-linux
fitbounds
flex-mobile
rmdir
cdonts
ie-compatibility-mode
delimited-text
zen
scrollbars
murmurhash
cuda.net
linfu-dynamicproxy
sqlobject
flvplayback
pbcopy

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