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

Touch focus recognition in android
Android and fuse.conf
Sharing with weibo sdk
Intent Service not working in doze mode
How to send class object through intent by implement parcable. Unable to marshal value error
Android keystore cannot resolve key
how to add gradient to image and text in frame layout
Resize image(Bitmap) as per aspect ratio without loosing quality of image android?
Android, RXJava, search using debounce
How to find views inside custom gridView to change them
Compile VLC Android fail “You must define ANDROID_NDK, ANDROID_SDK before starting.”
RecyclerView does not fully expand to show all elements
Enlarging Android Kernel Log Buffer more than 4MiB
html email signature not displaying inline css in gmail
FCM not working push notification sound android
Force close on break point

Categories

HOME
google-cloud-platform
porting
paraview
awk
c++11
telegram
css3
static
serialization
error-handling
ms-access-2016
static-site
regular-language
babeljs
trac
rcloud
okhttp
categorical-data
reactive-programming
pega
why3
magnetic-cards
template-engine
google-picker
digital-signature
boost-icl
dpdk
backpack-for-laravel
gulp-watch
hta
dapper-extensions
genexus-sd
testbed
angularjs-material
erb
hreflang
hunspell
servicestack-text
openalpr
z-notation
protein-database
metaprogramming
plaintext
android-softkeyboard
parser-generator
flask-restful
libgphoto2
netbeans6.8
activeperl
posixct
corruption
page-replacement
compiler-design
subnet
colorbar
opengl-4
pybrain
branch-prediction
visual-studio-2008-sp1
cubism.js
pacemaker
spring-cloud-feign
nikeplus-api
cifilter
vorpal.js
shopping
lua-telegram-bot
hadoop-partitioning
halcon
crouton-os
inf
grgit
intel-c++
fuelcms
visual-sourcesafe-2005
slash
uvc
rrule
qtwebengine
showdialog
webmatrix-3
formview
personalization
lnk
tinyxml
clickbank
gtm-oauth2
jammer
inputmismatchexception
kaleidoscope
poker
jquery-1.9
mysql-error-2013
chart-director
fb.ui
wimax
nokia-s40
paginator
extconf.rb
thttpd
box2d-iphone
node-redis
procedures
entity-attribute-value
creole
uipagecontrol
strsep
socketserver
collectionviewsource
cloudfiles
mtu
folding
lalr
complex-event-processing

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