Screen Slides. The Android Studio wizard adds a TextView to the fragment1.xml layout file and the necessary code to Fragment1.java.

Similar documents
Intents. Your first app assignment

Arrays of Buttons. Inside Android

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

Mobile Application Development Lab [] Simple Android Application for Native Calculator. To develop a Simple Android Application for Native Calculator.

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

ANDROID USER INTERFACE

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

Adapting to Data. Before we get to the fun stuff... Initial setup

ANDROID PROGRAMS DAY 3

EMBEDDED SYSTEMS PROGRAMMING UI Specification: Approaches

Android Tutorial: Part 3

Fragment Example Create the following files and test the application on emulator or device.

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

Creating a Custom ListView

ListView Containers. Resources. Creating a ListView

Overview. What are layouts Creating and using layouts Common layouts and examples Layout parameters Types of views Event listeners

Fragments. Lecture 11

CSE 660 Lab 3 Khoi Pham Thanh Ho April 19 th, 2015

05. RecyclerView and Styles

android-espresso #androidespresso

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Switching UIs

Tablets have larger displays than phones do They can support multiple UI panes / user behaviors at the same time

Produced by. Mobile Application Development. Eamonn de Leastar

Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB)

Action Bar. Action bar: Top navigation bar at each screen The action bar is split into four different functional areas that apply to most apps.

SD Module-1 Android Dvelopment

StoppUhr. <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="start1"

Mobile Application Development

User Interface Development. CSE 5236: Mobile Application Development Instructor: Adam C. Champion Course Coordinator: Dr.

Android Programs Day 5

Programming with Android: Introduction. Layouts. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Dynamically Create Admob Banner and Interstitial Ads

Getting Started With Android Feature Flags

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Fragments. Lecture 10

Android Application Model I. CSE 5236: Mobile Application Development Instructor: Adam C. Champion, Ph.D. Course Coordinator: Dr.

Mobile Computing Practice # 2c Android Applications - Interface

Create new Android project in Android Studio Add Button and TextView to layout Learn how to use buttons to call methods. Modify strings.

Android Application Model I

MVC Apps Basic Widget Lifecycle Logging Debugging Dialogs

Our First Android Application

University of Stirling Computing Science Telecommunications Systems and Services CSCU9YH: Android Practical 1 Hello World

PENGEMBANGAN APLIKASI PERANGKAT BERGERAK (MOBILE)

Adapter.

CS 4330/5390: Mobile Application Development Exam 1

android:orientation="horizontal" android:layout_margintop="30dp"> <Button android:text="button2"

Starting Another Activity Preferences

Android/Java Lightning Tutorial JULY 30, 2018

Android CardView Tutorial

ELET4133: Embedded Systems. Topic 15 Sensors

Open Lecture Mobile Programming. Intro to Material Design

8/30/15 MOBILE COMPUTING. CSE 40814/60814 Fall How many of you. have implemented a command-line user interface?

Mobile User Interfaces

Android UI Development

Tip Calculator. xmlns:tools=" android:layout_width="match_parent"

Embedded Systems Programming - PA8001

Developed and taught by well-known Contact author and developer. At public for details venues or onsite at your location.

Exercise 1: First Android App

Vienos veiklos būsena. Theory

Mobile Programming Lecture 1. Getting Started

Getting Started. Dr. Miguel A. Labrador Department of Computer Science & Engineering

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

Fragments were added to the Android API in Honeycomb, API 11. The primary classes related to fragments are: android.app.fragment

Android Navigation Drawer for Sliding Menu / Sidebar


Fragments. Fragments may only be used as part of an ac5vity and cannot be instan5ated as standalone applica5on elements.

Debojyoti Jana (Roll ) Rajrupa Ghosh (Roll ) Sreya Sengupta (Roll )

ActionBar. import android.support.v7.app.actionbaractivity; public class MyAppBarActivity extends ActionBarActivity { }

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 2

Upcoming Assignments Quiz Friday? Lab 5 due today Alpha Version due Friday, February 26

Chapter 5 Flashing Neon FrameLayout

THE CATHOLIC UNIVERSITY OF EASTERN AFRICA A. M. E. C. E. A

Android Application Development. By : Shibaji Debnath

CSE 660 Lab 7. Submitted by: Arumugam Thendramil Pavai. 1)Simple Remote Calculator. Server is created using ServerSocket class of java. Server.

M.A.D ASSIGNMENT # 2 REHAN ASGHAR BSSE 15126

External Services. CSE 5236: Mobile Application Development Course Coordinator: Dr. Rajiv Ramnath Instructor: Adam C. Champion

Mobile Software Development for Android - I397

M.A.D Assignment # 1

Lecture 14. Android Application Development

More Effective Layouts

Android Specifics. Jonathan Diehl (Informatik 10) Hendrik Thüs (Informatik 9)

Lab 6: Google Maps Android API v2 Android Studio 10/14/2016

Mobile Computing Fragments

TextView. A label is called a TextView. TextViews are typically used to display a caption TextViews are not editable, therefore they take no input

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Android User Interface Android Smartphone Programming. Outline University of Freiburg

Eng. Jaffer M. El-Agha Android Programing Discussion Islamic University of Gaza. Data persistence

Create Parent Activity and pass its information to Child Activity using Intents.

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Android Basics. Android UI Architecture. Android UI 1

Mobile Programming Lecture 5. Composite Views, Activities, Intents and Filters

Software Practice 3 Before we start Today s lecture Today s Task Team organization

Mobile Application Development MyRent Settings

Developing Android Applications Introduction to Software Engineering Fall Updated 1st November 2015

MAD ASSIGNMENT NO 2. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Mobile and Ubiquitous Computing: Android Programming (part 3)

Activities and Fragments

Orientation & Localization

Accelerating Information Technology Innovation

Transcription:

Screen Slides References https://developer.android.com/training/animation/screen-slide.html https://developer.android.com/guide/components/fragments.html Overview A fragment can be defined by a class and a layout file. It is used as a modular component in an activity. The activity can dynamically swap out one fragment for another. In this tutorial, you ll learn how to create an activity that initially loads one fragment, and when the user swipes left, replaces the first fragment with the second. To make this happen we ll do the following: 1. Create two fragments. 2. Create a new activity to hold the fragments. Create Two Fragments Create a new fragment by pressing File > New > Fragment > Fragment (Blank). On the Configure Component screen, name the fragment Fragment1 and name the layout fragment1. Uncheck the checkboxes blow the layout name and press Finish. The Android Studio wizard adds a TextView to the fragment1.xml layout file and the necessary code to Fragment1.java. Create a second fragment naming the fragment class Fragment2 and the layout file fragment2. Don t forget to uncheck the checkout boxes.

Once the files are created replace the TextView in fragment2.xml with a button that has its onclick property set to done. DO NOT, however, add a button handler named done to Fragment2.java. Create a New Activity Create a new activity by pressing File > New > Activity > Empty Activity. Name the activity MyActivity and name the layout my_activity. Replace the contents of my_activity.xml with the following code. <?xml version="1.0" encoding="utf-8"?> <android.support.v4.view.viewpager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" /> What we re doing here is putting a single widget (a ViewPager) in the activity s layout file. When the activity is loaded, the ViewPager will load (using an adapter) one of the fragments, and when the screen is swiped, the ViewPager will add a different fragment. Next, replace the contents of MyActivity.java with the code below. public class MyActivity extends FragmentActivity { private static final int NUM_PAGES = 2; private ViewPager mpager;

private PagerAdapter mpageradapter; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.my_activity); mpager = (ViewPager) findviewbyid(r.id.pager); mpageradapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); mpager.setadapter(mpageradapter); //optional: set to second page (starts at 0) mpager.setcurrentitem(1); public void onbackpressed() { if (mpager.getcurrentitem() == 0) { super.onbackpressed(); else { mpager.setcurrentitem(mpager.getcurrentitem() - 1);

private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); public Fragment getitem(int position) { if (position == 0) return new Fragment1(); else return new Fragment2(); public int getcount() { return NUM_PAGES; Notice that MyActivity extends FragmentActivity rather than AppCompatActivity. Notice too that we create an inner class named ScreenSlidePagerAdapter. An instance of this class is registered as the adapter (a data source) for the ViewPager. When the ViewPager needs a different fragment, the adapter serves it up by calling getitem().

Test the Code Create a button in one of your accessible activities so that when it is pressed MyActivity is loaded. When pressed, you should see fragment 1 initially displayed on the screen. When you swipe left, you should see the contents of Fragment2 (the button) come in from the right. At this point, the button should not work. Adding a Button Handler for the Done Button Recall that when you see fragment 1 or the done button on the screen, you re still actually viewing the MyAcitivity activity. If a button is displayed in an activity, regardless if it was placed there by a fragment or not, the button s onclick handler must be defined in the activity s class file. Add an onclick handler named done in MyActivity.java. Have the body of the function simply call finish(). When you run the app and press the done button, the app should return you to the activity that started MyActivity.