Is 389 android fragment lab ekedahl



Download 153.56 Kb.
Date20.06.2017
Size153.56 Kb.
#21149
IS 389 ANDROID FRAGMENT LAB

EKEDAHL

ABSTRACT


In this lab, you will work with Android Fragments. The application that you create for this lab will not do much, if any processing. Rather, it shows you the event lifecycle of adding and replacing fragments and how fragments are displayed within their container.

For this lab, I have posted the document electronically. I suggest that you load the Microsoft Word document. That way you can copy and paste my code into your lab. There is a significant amount of code in this program. For each code segment that you develop, there is a discussion of the code you have written. In some cases, you will modify the code on your own.


HANDS-ON EXERCISE: Creating the Layouts


For this application, you will need to create 5 layouts. Two of these layouts are used to render the activity while in portrait and landscape mode. The following list describes the activities.

  • The first layout is named activity_main.xml and appears in the layout folder. This layout will be rendered while the device is in portrait mode. This activity contains two buttons and two fragments that will be rendered vertically


  • The second layout is named activity_main.xml and appears in the layout-land folder. This layout will be rendered while the device is in landscape mode. The activity contains two buttons and two fragments that will be rendered horizontally.


There are three fragments. Each works the same way and will be rendered inside one of the parent activities.

  • The first fragment named fragment_one_layout.xml contains one TextView used to illustrate the activity and fragment events.


  • The second fragment named fragment_two_layout.xml contains one TextView used to illustrate the activity and fragment events.


  • The third fragment named fragment_three_layout.xml contains one TextView used to illustrate the activity and fragment events.

    The following excerpt from the Package Explorer shows the files and their folder location.






  1. Create a new Android Application project as you have been doing. I suggest using version 19 of the API’s. Create the application with a blank activity. Use the default name for the main activity. So that all of the names match, I suggest that you name the application (package) fragmentdemo1.


  2. Edit the file named activity_main.xml in the res/layout folder. Enter the following code:

"http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >


android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal" >


<Button

android:id="@+id/buttonOne"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="@string/replace_fragment" />


<Button

android:id="@+id/buttonTwo"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="@string/add_fragment" />




android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >


android:id="@+id/fragment_one_holder"

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_weight="1"

android:background="#6495ED" />


android:id="@+id/fragment_two_holder"

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_weight="1"

android:background="#40E0D0" />




Note the following about the preceding statements.



  • The activity uses an outer organized vertically (android:orientation="vertical").


  • There are two nested elements. The first contains two buttons appearing horizontally. The second contains two s organized vertically. These elements will render one of the three fragments:

Modify the strings.xml file appearing in the values folder adding the following lines (shown in bold).

"1.0" encoding="utf-8"?>


"app_name">FragmentDemo1

"hello_world">Hello world!

"action_settings">Settings

<string name="add_fragment">Add Fragmentstring>

<string name="replace_fragment">Replace Fragmentstring>

Next you will create a second activity. This activity will be displayed while the device is oriented in landscape mode.



  1. Create a folder named layout-land in the res folder. Remember that this name is magical based on the default configuration. This activity will be rendered when the device is in landscape mode.

Create a file named activity_main.xml in this folder and copy the following code into the file.

"http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >


android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal" >



Directory: faculty -> ekedahl -> IS389
faculty -> Curriculum vitae wei chen professor
faculty -> Digital image warping
faculty -> Samples of Elements Exam Question III contains All Prior Exam Qs III except
faculty -> 【Education&Working Experience】
faculty -> References Abe, M., A. Kitoh and T. Yasunari, 2003: An evolution of the Asian summer monsoon associated with mountain uplift —Simulation with the mri atmosphere-ocean coupled gcm. J. Meteor. Soc. Japan, 81
faculty -> Ralph R. Ferraro Chief, Satellite Climate Studies Branch, noaa/nesdis
faculty -> Unit IV text: Types of Oil, Types of Prices Grammar: that/those of, with revision
IS389 -> Installing java, eclipse, and android sdks to setup an android development environment
IS389 -> Lab creating a First Android Project
IS389 -> Please download a current copy. I have modified it since the initial upload

Download 153.56 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page