Android Studio Full Course
Android Studio Full Course
Java Folder the main code for the android app is stored in this folder.
MainActivity.java stores the code that runs when we launch our android
app.
Res Folder all the layout, resources, Menu and other important xml files.
Gradle Script allows us to run certain script at the time of Gradle
Building.
Logcat Displays all the task happening in the android Studio as well as the
emulator, it is very useful for debugging our android app.
onCreate() is a method which contains the code that runs when the
android app is opened
@Override is a keyword from JAVA which describes that the method
which we are creating is already created and we just want to add some
new code to it.
Just drag a button from the palette, set its onClick property to a method
and write some code inside that method.
Log.i(“nameoftag”,”Message Here”) prints out a message to the logcat
as an Information.
Q. Why we have View as a Parameter of a method?
A. Sometimes different components can have the same click method so if
we are having view as parameter we can use getId() or getTag() method
to use
public void buttonClicked(View view){
Log.i(“clickinfo”,”The user Clicked Here”);
}
To get text from a text field we first have to select its view then we have
to convert that view to EditText data type then we can use getText() and
toString() Method to get the text and convert it to a String.
public void buttonClicked(View view){
EditText newText = (EditText) findViewById(R.id.textView);
Log.i( “textinput”, newText.getText().toString() );
}
Toast is a message that appears in the bottom of the screen. We first
have to create a Toast then give it a context where it will appear then we
provide the string to output and then we provide the time for which it
will show, when all this is done we can use .show() method to show the
Toast to the user.
public void buttonClicked(View view){
Toast.makeText( getApplicationContext(), “Hi there”, Toast.LENGTH_SHORT).show();
}
To Display an image in out app we should have an Image. Copy any image
from your pc and paste it to the drawable folder inside the res folder of
app then just drag the Image view to the screen and then set the src
property of the image to the appropriate image and click Choose.
For Changing the Image when we Click On the Image:
Set the image onClick method to appropriate method.
public void imageClicked(View view){
ImageView img = (ImageView) findViewById(R.id.imageView);
Img.setImageResource(R.drawable.newImage);
}
We first dragged a textView then we get the text from that view by
getText() method then we converted it to a string then we just Use
Integer.parseInt() method to convert that string to integer then we
multiply it with amount of 1 Currency then we Toasted the Result to the
User.