Giter VIP home page Giter VIP logo

csci490-lab_02's Introduction

CSCI490-Lab_02

Lab to demonstrate building blocks and Intents

Instructions for Inclass Lab 02:

Problem

This lab will have you creating a button that will navigate you to another activity with the choice of two images to set the background of your first activity.

Purpose

This lab will introduce some basic features of calling an Intent to switch activities, perform an action on the sub Activity, and return a result back to the first Activity. Use of the values resource files will also be demonstrated.

Steps

Create Views:

  • Open Android Studio and create a basic project. Name the project whatever you like, IntentDemo is a good candidate. Choose API 23: Android 6.0 (Marshmallow). Next choose just an Empty Activity.
  • Place the two (2) images from Github into your drawable folder.
  • Create a Button at the bottom of activity_main.xml. Name the button "Set Background" (Be sure to use strings.xml)
  • Create another Activity class and associated layout. Name them whatever you would like.
  • In second layout file, create two (2) ImageView widgets. You can use whatever Layout you desire, but ContstraintLayout works just fine.
  • Link each ImageView with one of the images as shown in the screenshot.png and position/size the ImageView widgets.

Launch Second Activity

  • Add a reference to your second Activity in the AndroidManifest file.
  • In your main Activity, create a public static final int that will represent your request code.
  • Inside an onClick() for your button launch the second Activity. You will need to create an Intent and call startActivityForResult(). Pass in the intent you created and the request code.
  • In your main Activity, you will need to @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) and inside that block, grab the Layout like you would any other View item and call setBackground(getDrawable(imageID))
  • After you have code running on a device properly, refactor "hard coded" strings to be read from res/values/strings.xml
  • Share, commit, and push lab to your GitHub account

csci490-lab_02's People

Contributors

kabriggs991 avatar purtellap avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.