setId?? Can someone explail?

+1 Djole Su · July 24, 2015
i don't understand why are we using setId function in project "Alison"  and what is setId using for. 


usernameDetails.addRule(RelativeLayout.ABOVE, redButton.getId());

can't we just write?
usernameDetails.addRule(RelativeLayout.ABOVE, redButton);

Post a Reply


Oldest  Newest  Rating
+1 Tim Herreijgers · July 24, 2015
usernameDetails.addRule takes in two integers. One integer is the rule itself (RelativeLayout.ABOVE) the other integer is the view what it has to be above. But the redButton is a Button object. That why you set a id for the button.

And when you want to add a new button to an existing Activity that is using xml you dont have a Button object in Java. The addRule function uses an integer as an input for the view so you can use an id that you specified in a xml file.

I hope I answered your question
+1 Djole Su · July 25, 2015
thank you. l think l understand now :)
0 Mohammed AbuShanab · July 29, 2015
where can i find tutorial source code for any video pls
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator