Creating a Button: Android Programming

Demo of using Android Studio to create a simple application with a button which generates a log message and a toast.

1. Launch Android Studio; create simple hello-world app.
2. See XML and .java code for activities
3. Add a button, change name, see XML
4. Java code to access button: View.OnClickListener
5. Generate a log message when button is clicked.
6. Generate a toast when button is clicked.
7. Show where to find the compiled R class.

Listing of videos: http://www.cs.sfu.ca/CourseCentral/276/bfraser/videolist.html

TextView and strings.xml: Android Programming

Move strings from the layout into strings.xml for internationalization, access a TextView via Java code, and have Java code read from strings.xml.

1. Add a TextView, move text to strings.xml, change formatting.
2. Use Java to change the text on a TextView.
3. Use Java to load string from strings.xml and change text on TextView.

Uses a button for the demo, and briefly reviews an exception.

Listing of videos: http://www.cs.sfu.ca/CourseCentral/276/bfraser/videolist.html

Channel: DrBFraser
Published: 2017-01-09 08:26:30
Duration: 14M20S
Views: 85
Likes: 2
Favorites: 0

Switching Activities: Android Programming

Guide/demonstration to switching between activities in an Android program.
Steps listed below in the description.

Link to previous demo for creating a button:
http://www.youtube.com/watch?v=Uen8B9p05tI

Steps:
==========
1. Create the layout
– Create a new layout file under res/layout
– Named: second.xml
– Make it show something new (text field, icon…)

2. Create new Java class
– Create a new Java class: SecondScreen
– Override the onCreate():
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
}

3. Add activity to manifest
– Application tab, add new “Application Nodes”
– Add, “Create a new element at the TOP LEVEL”, Activity
– Set name: Select java class from above.
– Set Label (if desired)

4. Java code to switch activities
—————————
startActivity(new Intent( [Current Activity’s ‘this’], [New Activity’s Java].class));

Ex:
startActivity(new Intent(InClassDemoApp1.this, SecondScreen.class));

– Suggestion: Put launch code inside button callback:

Button daClicker = (Button) findViewById(R.id.button1);
daClicker.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, SecondScreen.class));
}
});

5. Activity Stack
=====================
– Loading an Activity are pushed on the Activity *Stack*
– Activity’s finish() method pops it
Returns to previous activity on stack.
– Must use correctly!

– Can move on and kill current activity:
startActivity(…);
finish();

6. Troubleshooting:
—————————
– Demonstrate what happens with the activity being in the manifest.
* View LogCat via DDMS:
…android.content.ActivityNotFoundException: Unable to find explicit activity class …; have you declared this activity in your AndroidManifest.xml?

Channel: DrBFraser
Published: 2013-02-05 06:58:18
Duration: 11M46S
Views: 66746
Likes: 352
Favorites: 0

Images & ImageButton: Android Programming

Demonstration on how to use images and an ImageButton in an Android project.
Covers:
– Adding images to your project.
– Explains different drawable resource folders
– Adding an ImageButton to an activity
– Fixing compile errors due to file name problems.
– Responding to click events on an ImageButton
– Changing the image on an ImageButton using a resource ID.
Channel: DrBFraser
Published: 2013-02-15 04:24:19
Duration: 12M19S
Views: 140206
Likes: 252
Favorites: 0

Internationalization: Android Tutorial

Demo covers how to translate a simple application into multiple languages using Google’s translation toolkit. Covers resources in layouts and Java code.
Full project source code: www.cs.sfu.ca/CC/276/bfraser/androidExampleCode/AndroidInternationalization.zip

Listing of videos: http://www.cs.sfu.ca/CourseCentral/276/bfraser/videolist.html

Channel: DrBFraser
Published: 2014-03-20 06:20:06
Duration: 16M28S
Views: 6444
Likes: 40
Favorites: 0

Clean & Zip Android Studio Project

How to clean the build products out of an Android Studio project folder and compress it.

Covers:
1. Show project folder in OS file viewer
2. Launch command prompt (Windows)
3. Run gradle: gradlew clean
4. Zip folder

Listing of videos: http://www.cs.sfu.ca/CourseCentral/276/bfraser/videolist.html

Channel: DrBFraser
Published: 2017-01-09 06:39:12
Duration: 3M38S
Views: 66
Likes: 4
Favorites: 0

Leave a Reply

Your email address will not be published. Required fields are marked *