SlideShare a Scribd company logo
1 of 31
Motorola Mobility Anna Schaller Android  기술 전도사 개발자 플랫폼 및 서비스 Fragment  소개
Fragment ,[object Object]
왜  Fragment 인가 ? ,[object Object],[object Object],Fragment 가 두 개인  Activity A 또는
준비  (Getting there) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],레이아웃에 대한 계획 수립
이중 창 ( 가로 및 세로 )
Fragment –  이중 창 Fragment  목록 Fragment Activity findFragmentById(R.id. DetailFragment ) setContentView(R.layout. main )
Android 3.0 에서  Fragment  작업하기 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
프로젝트 해부 – 이중 창만 해당 (Android 3.0) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
3.0  코드 :  main.java ,[object Object],[object Object]
3.0  코드 :  메인 레이아웃 fragment1  ( 목록 ) fragment2  ( 디테일 ) 가로 옆으로 나란히
3.0  코드 :  메인 레이아웃 세로 위에서 아래로 목록 폭 및 높이가  반전되어야 함
3.0  코드 :  Fragment  목록 목록 어댑터 설정  목록 항목  콜백 생성  이미지 업데이트  Activity  생성 후 실행할  새 수명 호출 디테일  Fragment  찾기
3.0  코드 :  Fragment  디테일 디테일 보기 를 올리고 첫 번째  이미지 로드  목록 위치를 기반으로 이미지 교체
3.0  코드 : Fragment UI (fragment1) 목록 항목 (fragment2) 프레임 항목 (ImageView  포함 )
[object Object],[object Object],UI 가 포함된  Fragment listfragment.xml <TextView> fragment.xml <FrameLayout> <ImageView> <LinearLayout> <GridView> [. . .] dialogfragment
UI 가 포함되지 않은  Fragment
findFragmentByTag() ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Android Compatibility( 호환 )  패키지 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
이중 창 (Android 2.2( 가로 방향 ))
단일 창 (Android 2.2( 세로 방향 ))
Fragment  –  이중 창 Fragment  목록 Fragment FragmentActivity1 findFragmentById(R.id. DetailFragment ) setContentView(R.layout. main )
Fragment  –  단일 창 Fragment Fragment Activity1 Fragment Activity2 Fragment  목록 setContentView(R.layout. main ) findViewById(R.id. DetailFragment )  is NULL intent.setClass(getActivity(),Fragment2. class); startActivity(intent );
Compatibility Library( 호환 라이브러리 )  수정 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
프로젝트 해부 – 이중 창  +  단일 창 (Android Compatibility  패키지 )  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Android Compatibility( 호환 )  패키지 이용 ,[object Object],[object Object],[object Object],[object Object],[object Object]
Fragment  사용 :  정보 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Fragment  사용 :  견본 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
자발적인   참여 : developer.motorola.com ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
감사합니다 © 2010 Motorola Mobility, Inc. 46
법적 고지  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

Similar to Introducing Fragments

1.Create Project Sunshine - 시온고등학교 안드로이드 스터디
1.Create Project Sunshine - 시온고등학교 안드로이드 스터디1.Create Project Sunshine - 시온고등학교 안드로이드 스터디
1.Create Project Sunshine - 시온고등학교 안드로이드 스터디Youngbin Han
 
[1A5]효율적인안드로이드앱개발
[1A5]효율적인안드로이드앱개발[1A5]효율적인안드로이드앱개발
[1A5]효율적인안드로이드앱개발NAVER D2
 
Agados Function and Feature Overview
Agados Function and Feature OverviewAgados Function and Feature Overview
Agados Function and Feature OverviewYongkyoo Park
 
Open Source Engineering V2
Open Source Engineering V2Open Source Engineering V2
Open Source Engineering V2YoungSu Son
 
Eclipse RAP - Single Source
Eclipse RAP - Single SourceEclipse RAP - Single Source
Eclipse RAP - Single Sourcecho hyun jong
 
2일차 20140402
2일차 201404022일차 20140402
2일차 20140402Jake Yoon
 
Android발표자료 홍종진
Android발표자료 홍종진Android발표자료 홍종진
Android발표자료 홍종진Jong Jin Hong
 
XECon2015 :: [3-2] 오승훈 - XE3 플러그인 제작 소개
XECon2015 :: [3-2] 오승훈 - XE3 플러그인 제작 소개XECon2015 :: [3-2] 오승훈 - XE3 플러그인 제작 소개
XECon2015 :: [3-2] 오승훈 - XE3 플러그인 제작 소개XpressEngine
 
Web app 개발 방법론
Web app 개발 방법론Web app 개발 방법론
Web app 개발 방법론Sang Seok Lim
 
[KGIT_EWD]class03 0322
[KGIT_EWD]class03 0322[KGIT_EWD]class03 0322
[KGIT_EWD]class03 0322jylee6977
 
[특강] 현업 개발자에게 듣는 모바일 개발자의 삶과 매력 / 노현석(카카오뱅크)
[특강] 현업 개발자에게 듣는 모바일 개발자의 삶과 매력 / 노현석(카카오뱅크)[특강] 현업 개발자에게 듣는 모바일 개발자의 삶과 매력 / 노현석(카카오뱅크)
[특강] 현업 개발자에게 듣는 모바일 개발자의 삶과 매력 / 노현석(카카오뱅크)CONNECT FOUNDATION
 
반복적인 작업이 싫은 안드로이드 개발자에게
반복적인 작업이 싫은 안드로이드 개발자에게반복적인 작업이 싫은 안드로이드 개발자에게
반복적인 작업이 싫은 안드로이드 개발자에게Sungju Jin
 
The Future of .NET and C#
The Future of .NET and C#The Future of .NET and C#
The Future of .NET and C#명신 김
 
Google app engine
Google app engineGoogle app engine
Google app enginescor7910
 
Angular 2 rc5 조사
Angular 2 rc5 조사Angular 2 rc5 조사
Angular 2 rc5 조사Rjs Ryu
 
Androidpn guide-0.5.0-ko
Androidpn guide-0.5.0-koAndroidpn guide-0.5.0-ko
Androidpn guide-0.5.0-kosandeepreddyp42
 
Ubuntu에서 Flask개발 맛보기 - 1
Ubuntu에서  Flask개발 맛보기 - 1Ubuntu에서  Flask개발 맛보기 - 1
Ubuntu에서 Flask개발 맛보기 - 1Booseol Shin
 
TestExplorer 소개 - Android application GUI testing tool
TestExplorer 소개 - Android application GUI testing toolTestExplorer 소개 - Android application GUI testing tool
TestExplorer 소개 - Android application GUI testing toolhyunae lee
 
TestExplorer 소개 - Android application GUI testing tool
TestExplorer 소개 - Android application GUI testing toolTestExplorer 소개 - Android application GUI testing tool
TestExplorer 소개 - Android application GUI testing toolhyunae lee
 

Similar to Introducing Fragments (20)

Designing Apps for Motorla Xoom Tablet
Designing Apps for Motorla Xoom TabletDesigning Apps for Motorla Xoom Tablet
Designing Apps for Motorla Xoom Tablet
 
1.Create Project Sunshine - 시온고등학교 안드로이드 스터디
1.Create Project Sunshine - 시온고등학교 안드로이드 스터디1.Create Project Sunshine - 시온고등학교 안드로이드 스터디
1.Create Project Sunshine - 시온고등학교 안드로이드 스터디
 
[1A5]효율적인안드로이드앱개발
[1A5]효율적인안드로이드앱개발[1A5]효율적인안드로이드앱개발
[1A5]효율적인안드로이드앱개발
 
Agados Function and Feature Overview
Agados Function and Feature OverviewAgados Function and Feature Overview
Agados Function and Feature Overview
 
Open Source Engineering V2
Open Source Engineering V2Open Source Engineering V2
Open Source Engineering V2
 
Eclipse RAP - Single Source
Eclipse RAP - Single SourceEclipse RAP - Single Source
Eclipse RAP - Single Source
 
2일차 20140402
2일차 201404022일차 20140402
2일차 20140402
 
Android발표자료 홍종진
Android발표자료 홍종진Android발표자료 홍종진
Android발표자료 홍종진
 
XECon2015 :: [3-2] 오승훈 - XE3 플러그인 제작 소개
XECon2015 :: [3-2] 오승훈 - XE3 플러그인 제작 소개XECon2015 :: [3-2] 오승훈 - XE3 플러그인 제작 소개
XECon2015 :: [3-2] 오승훈 - XE3 플러그인 제작 소개
 
Web app 개발 방법론
Web app 개발 방법론Web app 개발 방법론
Web app 개발 방법론
 
[KGIT_EWD]class03 0322
[KGIT_EWD]class03 0322[KGIT_EWD]class03 0322
[KGIT_EWD]class03 0322
 
[특강] 현업 개발자에게 듣는 모바일 개발자의 삶과 매력 / 노현석(카카오뱅크)
[특강] 현업 개발자에게 듣는 모바일 개발자의 삶과 매력 / 노현석(카카오뱅크)[특강] 현업 개발자에게 듣는 모바일 개발자의 삶과 매력 / 노현석(카카오뱅크)
[특강] 현업 개발자에게 듣는 모바일 개발자의 삶과 매력 / 노현석(카카오뱅크)
 
반복적인 작업이 싫은 안드로이드 개발자에게
반복적인 작업이 싫은 안드로이드 개발자에게반복적인 작업이 싫은 안드로이드 개발자에게
반복적인 작업이 싫은 안드로이드 개발자에게
 
The Future of .NET and C#
The Future of .NET and C#The Future of .NET and C#
The Future of .NET and C#
 
Google app engine
Google app engineGoogle app engine
Google app engine
 
Angular 2 rc5 조사
Angular 2 rc5 조사Angular 2 rc5 조사
Angular 2 rc5 조사
 
Androidpn guide-0.5.0-ko
Androidpn guide-0.5.0-koAndroidpn guide-0.5.0-ko
Androidpn guide-0.5.0-ko
 
Ubuntu에서 Flask개발 맛보기 - 1
Ubuntu에서  Flask개발 맛보기 - 1Ubuntu에서  Flask개발 맛보기 - 1
Ubuntu에서 Flask개발 맛보기 - 1
 
TestExplorer 소개 - Android application GUI testing tool
TestExplorer 소개 - Android application GUI testing toolTestExplorer 소개 - Android application GUI testing tool
TestExplorer 소개 - Android application GUI testing tool
 
TestExplorer 소개 - Android application GUI testing tool
TestExplorer 소개 - Android application GUI testing toolTestExplorer 소개 - Android application GUI testing tool
TestExplorer 소개 - Android application GUI testing tool
 

More from Motorola Mobility - MOTODEV

HTML5 vs Native Android: Smart Enterprises for the Future
HTML5 vs Native Android: Smart Enterprises for the FutureHTML5 vs Native Android: Smart Enterprises for the Future
HTML5 vs Native Android: Smart Enterprises for the FutureMotorola Mobility - MOTODEV
 
Getting Your App Discovered: Android Market & Beyond
Getting Your App Discovered: Android Market & BeyondGetting Your App Discovered: Android Market & Beyond
Getting Your App Discovered: Android Market & BeyondMotorola Mobility - MOTODEV
 
Gráficos cada vez más rápidos. Cómo usar NDK y RenderScript
Gráficos cada vez más rápidos. Cómo usar NDK y RenderScript Gráficos cada vez más rápidos. Cómo usar NDK y RenderScript
Gráficos cada vez más rápidos. Cómo usar NDK y RenderScript Motorola Mobility - MOTODEV
 
Consejos principales para Android UI Cómo alcanzar la magia en los tablets
Consejos principales para Android UI Cómo alcanzar la magia en los tabletsConsejos principales para Android UI Cómo alcanzar la magia en los tablets
Consejos principales para Android UI Cómo alcanzar la magia en los tabletsMotorola Mobility - MOTODEV
 
Cómo agregar calidad a sus aplicaciones mediante pruebas
Cómo agregar calidad a sus aplicaciones mediante pruebas Cómo agregar calidad a sus aplicaciones mediante pruebas
Cómo agregar calidad a sus aplicaciones mediante pruebas Motorola Mobility - MOTODEV
 
Cómo aprovechar Webtop Cómo HTML5 mejora la experiencia del usuario
Cómo aprovechar Webtop Cómo HTML5 mejora la experiencia del usuarioCómo aprovechar Webtop Cómo HTML5 mejora la experiencia del usuario
Cómo aprovechar Webtop Cómo HTML5 mejora la experiencia del usuarioMotorola Mobility - MOTODEV
 
Gráficos cada vez mais rápidos utilização de NDK e Renderscript
Gráficos cada vez mais rápidos utilização de NDK e RenderscriptGráficos cada vez mais rápidos utilização de NDK e Renderscript
Gráficos cada vez mais rápidos utilização de NDK e RenderscriptMotorola Mobility - MOTODEV
 
Como integrar qualidade aos seus aplicativos através de testes
Como integrar qualidade aos seus aplicativos através de testesComo integrar qualidade aos seus aplicativos através de testes
Como integrar qualidade aos seus aplicativos através de testesMotorola Mobility - MOTODEV
 
Tirando vantagem do webtop como o html5 aprimora a experiência do usuário de ...
Tirando vantagem do webtop como o html5 aprimora a experiência do usuário de ...Tirando vantagem do webtop como o html5 aprimora a experiência do usuário de ...
Tirando vantagem do webtop como o html5 aprimora a experiência do usuário de ...Motorola Mobility - MOTODEV
 

More from Motorola Mobility - MOTODEV (20)

HTML5 vs Native Android: Smart Enterprises for the Future
HTML5 vs Native Android: Smart Enterprises for the FutureHTML5 vs Native Android: Smart Enterprises for the Future
HTML5 vs Native Android: Smart Enterprises for the Future
 
Kill the Laptop!
Kill the Laptop!Kill the Laptop!
Kill the Laptop!
 
MOTODEV App Validator
MOTODEV App ValidatorMOTODEV App Validator
MOTODEV App Validator
 
Beautifully Usable, Multiple Screens Too
Beautifully Usable, Multiple Screens TooBeautifully Usable, Multiple Screens Too
Beautifully Usable, Multiple Screens Too
 
Getting the Magic on Android Tablets
Getting the Magic on Android TabletsGetting the Magic on Android Tablets
Getting the Magic on Android Tablets
 
Getting Your App Discovered: Android Market & Beyond
Getting Your App Discovered: Android Market & BeyondGetting Your App Discovered: Android Market & Beyond
Getting Your App Discovered: Android Market & Beyond
 
Taking Advantage of Webtop
Taking Advantage of WebtopTaking Advantage of Webtop
Taking Advantage of Webtop
 
Building Quality Into Your Apps Through Testing
Building Quality Into Your Apps Through TestingBuilding Quality Into Your Apps Through Testing
Building Quality Into Your Apps Through Testing
 
Top Tips for Android UIs
Top Tips for Android UIsTop Tips for Android UIs
Top Tips for Android UIs
 
Diseñando aplicaciones para el Motorola XOOM
Diseñando aplicaciones para el Motorola XOOM Diseñando aplicaciones para el Motorola XOOM
Diseñando aplicaciones para el Motorola XOOM
 
Presentación de los fragmentos
Presentación de los fragmentos Presentación de los fragmentos
Presentación de los fragmentos
 
Gráficos cada vez más rápidos. Cómo usar NDK y RenderScript
Gráficos cada vez más rápidos. Cómo usar NDK y RenderScript Gráficos cada vez más rápidos. Cómo usar NDK y RenderScript
Gráficos cada vez más rápidos. Cómo usar NDK y RenderScript
 
Consejos principales para Android UI Cómo alcanzar la magia en los tablets
Consejos principales para Android UI Cómo alcanzar la magia en los tabletsConsejos principales para Android UI Cómo alcanzar la magia en los tablets
Consejos principales para Android UI Cómo alcanzar la magia en los tablets
 
Cómo agregar calidad a sus aplicaciones mediante pruebas
Cómo agregar calidad a sus aplicaciones mediante pruebas Cómo agregar calidad a sus aplicaciones mediante pruebas
Cómo agregar calidad a sus aplicaciones mediante pruebas
 
Cómo aprovechar Webtop Cómo HTML5 mejora la experiencia del usuario
Cómo aprovechar Webtop Cómo HTML5 mejora la experiencia del usuarioCómo aprovechar Webtop Cómo HTML5 mejora la experiencia del usuario
Cómo aprovechar Webtop Cómo HTML5 mejora la experiencia del usuario
 
Principais dicas para UIs do Android
Principais dicas para UIs do AndroidPrincipais dicas para UIs do Android
Principais dicas para UIs do Android
 
Gráficos cada vez mais rápidos utilização de NDK e Renderscript
Gráficos cada vez mais rápidos utilização de NDK e RenderscriptGráficos cada vez mais rápidos utilização de NDK e Renderscript
Gráficos cada vez mais rápidos utilização de NDK e Renderscript
 
Como integrar qualidade aos seus aplicativos através de testes
Como integrar qualidade aos seus aplicativos através de testesComo integrar qualidade aos seus aplicativos através de testes
Como integrar qualidade aos seus aplicativos através de testes
 
Tirando vantagem do webtop como o html5 aprimora a experiência do usuário de ...
Tirando vantagem do webtop como o html5 aprimora a experiência do usuário de ...Tirando vantagem do webtop como o html5 aprimora a experiência do usuário de ...
Tirando vantagem do webtop como o html5 aprimora a experiência do usuário de ...
 
Introdução a fragmentos
Introdução a fragmentosIntrodução a fragmentos
Introdução a fragmentos
 

Introducing Fragments

  • 1. Motorola Mobility Anna Schaller Android 기술 전도사 개발자 플랫폼 및 서비스 Fragment 소개
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. 이중 창 ( 가로 및 세로 )
  • 7. Fragment – 이중 창 Fragment 목록 Fragment Activity findFragmentById(R.id. DetailFragment ) setContentView(R.layout. main )
  • 8.
  • 9.
  • 10.
  • 11. 3.0 코드 : 메인 레이아웃 fragment1 ( 목록 ) fragment2 ( 디테일 ) 가로 옆으로 나란히
  • 12. 3.0 코드 : 메인 레이아웃 세로 위에서 아래로 목록 폭 및 높이가 반전되어야 함
  • 13. 3.0 코드 : Fragment 목록 목록 어댑터 설정 목록 항목 콜백 생성 이미지 업데이트 Activity 생성 후 실행할 새 수명 호출 디테일 Fragment 찾기
  • 14. 3.0 코드 : Fragment 디테일 디테일 보기 를 올리고 첫 번째 이미지 로드 목록 위치를 기반으로 이미지 교체
  • 15. 3.0 코드 : Fragment UI (fragment1) 목록 항목 (fragment2) 프레임 항목 (ImageView 포함 )
  • 16.
  • 17. UI 가 포함되지 않은 Fragment
  • 18.
  • 19.
  • 20. 이중 창 (Android 2.2( 가로 방향 ))
  • 21. 단일 창 (Android 2.2( 세로 방향 ))
  • 22. Fragment – 이중 창 Fragment 목록 Fragment FragmentActivity1 findFragmentById(R.id. DetailFragment ) setContentView(R.layout. main )
  • 23. Fragment – 단일 창 Fragment Fragment Activity1 Fragment Activity2 Fragment 목록 setContentView(R.layout. main ) findViewById(R.id. DetailFragment ) is NULL intent.setClass(getActivity(),Fragment2. class); startActivity(intent );
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30. 감사합니다 © 2010 Motorola Mobility, Inc. 46
  • 31.

Editor's Notes

  1. Starting from Android 1.6 and up developers can divide the Activities of their applications into subcomponents called Fragments. Fragments -- can be added, removed, replaced, and animated inside an Activity dynamically -- are modular and reusable across multiple Activities. Here we’ve got the updated version of the contacts app showing the list of contacts in a fragment on the left and the details of the selected contact in a fragment on the right.
  2. Figure out what you want your fragments to look like on different size screens and different orientations on those screens. Take advantage of the qualifiers for size and layout. Think about your use-cases. Tablet experience is very different than smartphone experience
  3. So this my dual pane application build against Android 3.0. Two layouts (landscape and portrait) each with two panes.
  4. In each case we start with 2 fragments inside an activity. As I mentioned earlier, fragments cannot live outside an Activity. When you run your application the main activity will load the main resource file (main.xml) that defines the layout for the entire application. You then attach fragments together with findFragmentId(). In this case we are attaching the detail fragment to the listFragment.
  5. So how do you get this with Honeycomb. This is a pretty broad brush list but it should point you in the right direction. For each fragment you’ll need to create a new class. You can do this inside one java file or create separate java files for each class. You need to import android.app.Fragment (as well as FragmentManager). The fragments extend the Fragment class instead of the Activity class. Then add your lifecycle calls. Next you should create resource files for each fragment defining the layout for that fragment. You’ll add the fragments to the application by adding the fragment tag to the applications XML file. Remember to give it an ID. Lastly you’ll update your main Activity by first importing the fragment package. You then load the application UI with findViewById() – same as you’ve always done. To communicate with the fragment you’ll call findFragmentById() and give it the ID you defined for that fragment. In our example we daisy chain the fragments so the listFragment communicates with the content fragment with a call to findFragmentId() from the list.
  6. So this is what your Android project would look like after you’re done creating a dual pane layout with fragments using Android 3.0. You’ll have your main activity along with 2 or more fragments. In your resource folder you’ll have a layout for landscape and portrait (if you want it to look differently). Your layout for the application as a whole is still defined in your main.xml and each fragment then has their UI defined in their own XML files. The difference in layouts between landscape and portrait is mainly the direction the fragments are displayed in.
  7. So lets walk through the code. The main.java file is your activity. I’ve defined FragmentsHCDemo to extend Activity. In the onCreate() I call setContentView() with the activities layout file. This loads the resource file that contains the &lt;fragment&gt; definitions. The fragments are instantiated as soon as the activity loads the layout.
  8. The layout file itself has a LinearLayout as it’s container and 2 &lt;fragment&gt; tags, each one defining the class name of the fragment as well as the properties of the fragment. This is the layout file for the landscape mode so I need to specify the orientation to be horizontal. Otherwise the LinearLayout defaults to top-to-bottom. So take a look at the properties for the first fragment – my list fragment. It has an id, followed by a layout_width (which in landscape mode is 200dp) and layout_height (which is set to match the parent).
  9. If we look at the portrait version of that layout file there are a few things that change. First the orientation is now vertical (or top-to-bottom). The width and height of the list also need to be reversed. If I had left it alone the list would have expanded to fill the parent and there would be no room for the detail fragment.
  10. There are 2 fragment files. This is the listFragment. As you can see we need to extend the ListFragment. There’s also a new set of lifecycle calls for fragments, one of which is onActivityCreated(). This is called after the main activity has completed it’s onCreate() call. In here we create a list adapter the same way you would inside an activity. Along with that list adapter you need a callback to handle selecting each list item which we’ve done with onListItemClick(). This is where you need to attach to your detail fragment. Each time we select something from the list a call is made to findFragmentById() and we pass in the id of the detail fragment that was defined in the main.xml file. Once we’ve located it, we then call into the detail fragment to update the image.
  11. Then if we look at the detail fragment, you are extending a Fragment, calling one of the other new lifecycle calls for fragments – onCreateView(), inflating the layout for that detail fragment, and setting the initial image. Below that is the routine to update the image every time a list item is selected. You are passing in the position of the selected list item, locating the appropriate drawable, and setting the ImageView to that drawable.
  12. The layout files for each of the fragments is pretty straightforward. The listFragment only defines the textView for the items in the list. The detail fragment uses a FrameLayout as it’s container and defines an ImageView to hold the images.
  13. So you’ve got this big screen and you want to take advantage of it with fragments. You can use the same views and viewgroups in a fragment that you use in an Activity. You don’t have to use a listFragment; you can have two fragments side-by-side. Be creative.
  14. Don’t need a resource file since there is no UI Don’t need a fragment tag in the main activity either. However without that definition there is no longer an id associated with the fragment so you’ll need to use a “tag” to get to that fragment. Easier than using the raw Activity.onRetainNonConfigurationInstance() API
  15. Programmatically, you still define your fragment by extending a Fragment. Then (working from the bottom up) the first time you need to use that fragment you would have to instantiate it with a call to new(). You would then attach to that fragment with a call to “add” and supply a name, or tag, for that fragment. Since it’s considered a transaction you need to surround it with beginTransaction() and commit(). Thereafter you can locate that fragment with a call to findFragmentByTag() supplying the name you gave it when you first added it.
  16. So let’s say you want your app to look like this in landscape mode on ANY device (this happens to be on a XOOM)
  17. And you want it to look like this in portrait mode (this happens to be an ATRIX)
  18. To get your dual pane it’s pretty much the same logic as it is on Android 3.0. You need a main activity but in the Compatibility library it’s now called a “FragmentActivity”. You still need to create each fragment by subclassing the appropriate fragment type. You still need to define a UI for each fragment. And you still need to add a fragment tag to the main activities layout file. A call to findFragmentId() is used to locate and perform any operations on that fragment.
  19. Single pane logic (for instance for portrait) gets interesting. First of all this way of displaying fragments is based on the orientation. So you’ll need to check whether you’re in portrait mode or not. If so instead of calling findFragmentById() from the listFragment you’ll start a new activity for the detail by way of intents. Since fragments can’t live outside of an Activity you need to define a FragmentActivity for each fragment.
  20. In the end this is what your project will contain. You’ll have two FragmentActivites and two fragments. The main activity locates fragment1 with findFragmentById(). Fragment1 loads fragment2 by launching an intent to start the second activity. You landscape layout stays the same but your portrait layout for your activity only contains the fragment tag for the first fragment. When you call setContentView(), only one fragment is loaded.