Vous êtes sur la page 1sur 6

Resources

Android App is made of Resources and Java Code.

Java code consists of files like MainActivity.java. Altogether it handles what should happen when
the app is running.
Resources exists in the res directory of our app. It includes, images, text- colors, dimensions
width and height, XML files, raw media files Audio and Video.

Accessing Resources
There is tool in Android Studio known as aapt that generates the R class when application is
compiled. R class contains resource IDs for all of the resources in the res directory.

In Java code, there are several resource types but we commonly use the resource types as shown
in figure .

1
From XML to Java

When setContentView method is invoked, it allows to inflate the objects using Java in a
hierarchical manner.

An object like TextView contains state information e.g. textcolor, textsize.

The object also includes methods so that we can call the methods and change their internal
state. For e.g. while running the app we can change the state of the text.

Hence interacting with objects is known as Object-Oriented Programming.

Object has State and Methods


Displaying of TextView on the screen is controlled by a Java object. It is an example of TextView
object. It holds particular state.

State is made of bunch of fields. Field is similar to variable. Text field can be used for storing
string parameter whereas Integer field can be used for storing font size of text.

To interact with TextView object and make changes on it while app is run, we can call certain
methods on the TextView (only can be done in the mainactivity.java file) to modify state or
perform more complex operation.

Android performs execution of interacting with objects automatically, but it is useful to call these
methods to change an object.

We can know what all of the fields are inside the state and methods included in TextView object,
we can investigate its class definition.

2
Java Classes
In the real world, you'll often find many individual objects all of the same kind. There may be thousands of
other bicycles in existence, all of the same make and model. Each bicycle was built from the same set of
blueprints and therefore contains the same components. In object-oriented terms, we say that your bicycle
is an instance of the class of objects known as bicycles. A class is the blueprint from which individual
objects are created.

3
Creating Object with Constructor

4
Creating Object by Factory Method

Call Method on Object

5
6

Vous aimerez peut-être aussi