Android Development – User Interface

As I had said in the “first thoughts” about Android Development, the user interface of the app is written in Xml code. What does that really mean to the programmer? Well, it means that components such as buttons, radio buttons, textviews, etc are all going to be in the Xml file.

Using Xml Components with Java Code:

If we want to use the User Interface components in our java code. For Example, if we want to do something when a button is pressed then we must add an action listener to the button just like when create desktop applications. But first we must create an object of a button in the activities .java file, and then we must find the button from the activities .xml file and link it the button from the .java file. We do something like this:

 

 

In the code above we can see that the “enterButton” button was set to “(Button)findViewById(R.id.enter_Button);” that line of code is the one that finds the button on the xml file. Once we find it then we can do everything that we would do to a button such as add an action listener, write code to be executed when the action listener is triggered. Hope you enjoyed this. Keep coding on!

Leave a comment