We can use the Logic element inside mainactivity.java and write the same code and then it can be done that way. It is upto user to choose which part of activity such as design or logic part to choose. The design part is easier as it is drag and drop element. The logic part is for geeks who want to comprehensively understands the how the logic of coding in relation with design element works and it is completely yours choice to choose which part.