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. 
 
redButton.setId(1);
username.setId(2);

and 

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

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

Post a Reply

Replies

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

106,961 followers
About

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

Links
Moderators
Bucky Roberts Administrator