CS 2340
how to navigate
ANDROid studio
Team 45
Installing Android Studio
CS 2340
CLICK ME!
Creating a Project
Open Android Studio.
Click [New Project].
Select [Basic Views Activity], then Click [Next].
Give your application a name such as My First App.
Make sure the Language is set to Java.
This will...
Leave the defaults for the other fields. (The SDK and Build Configuration Language is not important for this tutorial)
Click [Finish].
CS 2340
Running your app on a device/emulator
On the top right, click on [Device Manager]
Click on [Create Virtual Device]
Click [Next] until [Finish] appears
Click [Run ‘app’] on the top to run
CS 2340
Adding interactive buttons
On the top left, click [App→ res → fragment_first.xml]
Click and pull out a button in [Palette→Common → Button]
CS 2340
Displaying Second Screen
When the button is pressed
Using the Layout Editor
Looking to the left...
Examine the Component Tree in the fragment_first.xml file. (If it is not visible, change the mode to Design instead of Split or Code)
Setting property values...
Setting
Color resources
CS2340
Code whatever colors you want
Similar to setting property values...
Austen Tech
Examine the navigation graph
A screen similar to the Layout Editor in Design view appears. It shows the two fragments with some arrows between them. You can zoom with + and - buttons in the lower right, as you did with the Layout Editor. You can freely move the elements in the navigation editor.
For example, if the fragments appear with SecondFragment to the left, drag FirstFragment to the left of SecondFragment so they appear in the order you work with them.
Enable SafeArgs
01
02
03
Open Gradle Scripts > build.gradle (Project: “”)
find dependencies section in the buildscript section, and add:
Open Gradle Scripts > build.gradle (App: “”)
04
Add a line to enable SafeArgs below:
04
Click Sync Now
Create the argument for the navigation action
In the navigation graph, click on FirstFragment, and look at the Attributes panel to the right.
Click on SecondFragment, and look at the Attributes panel.
Click on the + in the Arguments section.
In the Add Argument dialog, enter myArg for the name and set the type to Integer, then click the Add button.
Sending the count to the second fragment
Open FirstFragment.java
(app > java > com.example.myfirstapp > FirstFragment)
Find the method onViewCreated()
Look for the section of code that sets up the click listener to go from the first fragment to the second.
Replace the code in that click listener with a line to find the count text view, textview_first.
int currentCount = Integer.parseInt(ShowCountTextView.getText().toString();
Thank you!
Feel free to approach us if you have any questions.