SlideShare a Scribd company logo
1 of 7
Download to read offline
[IOS말고 ANDROID] Inflation을 이용하여 부분 Activity 띄우기 #inflation #inflater #getSystemService
Inflation을 이용하여 부분 Activity 띄우기
lsh00124@naver.com 이상훈
<activity_main.xml> <sub_layout.xml>
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
MainActivity는 onCreate()에서 이미 메모리상에 올려 놓았다.
따라서 findViewById를 통해 container 레이아웃을 찾을 수 있다.
하지만 sub_layout.xml은 그렇지 않다.
그래서 inflater를 이용하여 우선적으로
메모리상에 올려놔야 나중에 가져올 수 있다.
getSystemService를 통해서 시스템 객체를 참
조한다. 이것은 여러 개의 type이 있기 때문에
LayoutInflater로 casting한다.
public void button1Clicked(View v){
//MainActivity.java는 'setContentView(R.layout.activity_main)'를 통해서
//메모리에 올렸기 때문에 findViewById를 통해 container 레이아웃을 바로 찾는다.
LinearLayout container = (LinearLayout)findViewById(R.id.container);
//inflater는 메모리 상에 올려준다.
//즉 객체화등을 통해 뷰그룹 같은 것을 사용할 수 있게 해준다.
//getSystemService를 통해서 시스템객체를 참조한다.
//getSystemService는 여러개의 타입이 있어서 LayoutInflater 타입으로 casting한다.
LayoutInflater inflater =
(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//inflater의 inflate를 통해서 sub_layout을 메모리상에 올리고 container에 붙여준다.
inflater.inflate(R.layout.sub_layout, container, true);
//sub_layout이 메모리 상에 있기 때문에 이 안에 있는 뷰그룹을 사용할 수 있다.
Button button = (Button)findViewById(R.id.button2);//container.findViewById도 됨.
button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"부분화면의 버튼이 눌러졌습니다",
Toast.LENGTH_LONG).show();
}
});
public void button1Clicked(View v){
//MainActivity.java는 'setContentView(R.layout.activity_main)'를 통해서
//메모리에 올렸기 때문에 findViewById를 통해 container 레이아웃을 바로 찾는다.
LinearLayout container = (LinearLayout)findViewById(R.id.container);
//inflater는 메모리 상에 올려준다.
//즉 객체화등을 통해 뷰그룹 같은 것을 사용할 수 있게 해준다.
//getSystemService를 통해서 시스템객체를 참조한다.
//getSystemService는 여러개의 타입이 있어서 LayoutInflater 타입으로 casting한다.
LayoutInflater inflater =
(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//inflater의 inflate를 통해서 sub_layout을 메모리상에 올리고 container에 붙여준다.
inflater.inflate(R.layout.sub_layout, container, true);
//sub_layout이 메모리 상에 있기 때문에 이 안에 있는 뷰그룹을 사용할 수 있다.
Button button = (Button)findViewById(R.id.button2);//container.findViewById도 됨.
button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"부분화면의 버튼이 눌러졌습니다",
Toast.LENGTH_LONG).show();
}
});
inflate()를 이용해서 sub_layout을 메모리
상에 올리고 container에 붙여준다.
버튼을 클릭했을때 Toast message를 띄워
주기 위해 sub_layout 상의 버튼을 가져와
야 하는데, 이떄 sub_layout은 inflate()를
통해서 메모리상에 올려 놓았기 때문에 바
로 참조하여 가져올 수 있다.
container.findViewById()를 통해 참조를
해야하는데 그냥 findeViewById()를 해도
참조가 된다.
activity_main에서 '부분화면 띄우기' 버튼을 클릭하면 container layout 상에 sub_layout이 띄워진다.
sub_layout상에는 '부분화면에서 버튼클릭이벤트' 버튼이 있는데 이것을 클릭하면 Toast message가 뜬다.

More Related Content

Similar to [IOS말고 Android] Inflation을 이용하여 부분 Activity 띄우기

Android 기초강좌 애플리캐이션 구조
Android 기초강좌 애플리캐이션 구조Android 기초강좌 애플리캐이션 구조
Android 기초강좌 애플리캐이션 구조Sangon Lee
 
React Hooks 마법. 그리고 깔끔한 사용기
React Hooks 마법. 그리고 깔끔한 사용기React Hooks 마법. 그리고 깔끔한 사용기
React Hooks 마법. 그리고 깔끔한 사용기NAVER SHOPPING
 
Vue guide예제(vue todo-list)-v0.1
Vue guide예제(vue todo-list)-v0.1Vue guide예제(vue todo-list)-v0.1
Vue guide예제(vue todo-list)-v0.1DataUs
 
Storyboard iOS 개발실습예제
Storyboard iOS 개발실습예제Storyboard iOS 개발실습예제
Storyboard iOS 개발실습예제Sangon Lee
 
[방송통신대 컴퓨터과학과] 2020년 1학기 전공 모바일 앱 프로그래밍 기말평가 제출본
[방송통신대 컴퓨터과학과] 2020년 1학기 전공 모바일 앱 프로그래밍 기말평가 제출본[방송통신대 컴퓨터과학과] 2020년 1학기 전공 모바일 앱 프로그래밍 기말평가 제출본
[방송통신대 컴퓨터과학과] 2020년 1학기 전공 모바일 앱 프로그래밍 기말평가 제출본Lee Sang-Ho
 
Vue.js 기초 실습.pptx
Vue.js 기초 실습.pptxVue.js 기초 실습.pptx
Vue.js 기초 실습.pptxwonyong hwang
 
Youtube를활용한app만들기
Youtube를활용한app만들기Youtube를활용한app만들기
Youtube를활용한app만들기DaeHee Jang
 
Component, Redux 기반 비디오 구조 제안
Component, Redux 기반 비디오 구조 제안Component, Redux 기반 비디오 구조 제안
Component, Redux 기반 비디오 구조 제안Young-Hyuk Yoo
 

Similar to [IOS말고 Android] Inflation을 이용하여 부분 Activity 띄우기 (11)

Android 기초강좌 애플리캐이션 구조
Android 기초강좌 애플리캐이션 구조Android 기초강좌 애플리캐이션 구조
Android 기초강좌 애플리캐이션 구조
 
React Hooks 마법. 그리고 깔끔한 사용기
React Hooks 마법. 그리고 깔끔한 사용기React Hooks 마법. 그리고 깔끔한 사용기
React Hooks 마법. 그리고 깔끔한 사용기
 
2. widget
2. widget2. widget
2. widget
 
Vue guide예제(vue todo-list)-v0.1
Vue guide예제(vue todo-list)-v0.1Vue guide예제(vue todo-list)-v0.1
Vue guide예제(vue todo-list)-v0.1
 
Storyboard iOS 개발실습예제
Storyboard iOS 개발실습예제Storyboard iOS 개발실습예제
Storyboard iOS 개발실습예제
 
[방송통신대 컴퓨터과학과] 2020년 1학기 전공 모바일 앱 프로그래밍 기말평가 제출본
[방송통신대 컴퓨터과학과] 2020년 1학기 전공 모바일 앱 프로그래밍 기말평가 제출본[방송통신대 컴퓨터과학과] 2020년 1학기 전공 모바일 앱 프로그래밍 기말평가 제출본
[방송통신대 컴퓨터과학과] 2020년 1학기 전공 모바일 앱 프로그래밍 기말평가 제출본
 
Vue.js 기초 실습.pptx
Vue.js 기초 실습.pptxVue.js 기초 실습.pptx
Vue.js 기초 실습.pptx
 
Youtube를활용한app만들기
Youtube를활용한app만들기Youtube를활용한app만들기
Youtube를활용한app만들기
 
iOS9 소개
iOS9 소개iOS9 소개
iOS9 소개
 
Actionbar and fragment
Actionbar and fragmentActionbar and fragment
Actionbar and fragment
 
Component, Redux 기반 비디오 구조 제안
Component, Redux 기반 비디오 구조 제안Component, Redux 기반 비디오 구조 제안
Component, Redux 기반 비디오 구조 제안
 

More from SangHun Lee

PWA 파헤치기
PWA 파헤치기PWA 파헤치기
PWA 파헤치기SangHun Lee
 
Angular CodeLab 두번째
Angular CodeLab 두번째Angular CodeLab 두번째
Angular CodeLab 두번째SangHun Lee
 
Angular CodeLab 첫번째
Angular CodeLab 첫번째Angular CodeLab 첫번째
Angular CodeLab 첫번째SangHun Lee
 
Angular Popular Tools
Angular Popular ToolsAngular Popular Tools
Angular Popular ToolsSangHun Lee
 
Chrome 69 updates
Chrome 69 updatesChrome 69 updates
Chrome 69 updatesSangHun Lee
 
Angular Component Interaction
Angular Component InteractionAngular Component Interaction
Angular Component InteractionSangHun Lee
 
Chrome 68 updates
Chrome 68 updatesChrome 68 updates
Chrome 68 updatesSangHun Lee
 
Reactive Programming with Rxjs
Reactive Programming with RxjsReactive Programming with Rxjs
Reactive Programming with RxjsSangHun Lee
 
Angular Features and New Things
Angular Features and New ThingsAngular Features and New Things
Angular Features and New ThingsSangHun Lee
 
Ror 4주차(루비맛보기, form 태그)
Ror 4주차(루비맛보기, form 태그)Ror 4주차(루비맛보기, form 태그)
Ror 4주차(루비맛보기, form 태그)SangHun Lee
 
Ror 2주차(컨트롤러 생성)
Ror 2주차(컨트롤러 생성)Ror 2주차(컨트롤러 생성)
Ror 2주차(컨트롤러 생성)SangHun Lee
 
루비온레일즈_01_간단한 정적인 홈페이지 제작
루비온레일즈_01_간단한 정적인 홈페이지 제작루비온레일즈_01_간단한 정적인 홈페이지 제작
루비온레일즈_01_간단한 정적인 홈페이지 제작SangHun Lee
 
Basic of web ref.웹을지탱하는기술_02
Basic of web ref.웹을지탱하는기술_02Basic of web ref.웹을지탱하는기술_02
Basic of web ref.웹을지탱하는기술_02SangHun Lee
 
Eclipse rcp 정리(enabled when, contextmenu)
Eclipse rcp 정리(enabled when, contextmenu)Eclipse rcp 정리(enabled when, contextmenu)
Eclipse rcp 정리(enabled when, contextmenu)SangHun Lee
 
Basic of web ref.웹을지탱하는기술_01
Basic of web ref.웹을지탱하는기술_01Basic of web ref.웹을지탱하는기술_01
Basic of web ref.웹을지탱하는기술_01SangHun Lee
 

More from SangHun Lee (20)

PWA 파헤치기
PWA 파헤치기PWA 파헤치기
PWA 파헤치기
 
Angular Library
Angular LibraryAngular Library
Angular Library
 
Angular CodeLab 두번째
Angular CodeLab 두번째Angular CodeLab 두번째
Angular CodeLab 두번째
 
Angular CodeLab 첫번째
Angular CodeLab 첫번째Angular CodeLab 첫번째
Angular CodeLab 첫번째
 
Angular Popular Tools
Angular Popular ToolsAngular Popular Tools
Angular Popular Tools
 
Chrome 69 updates
Chrome 69 updatesChrome 69 updates
Chrome 69 updates
 
Angular Component Interaction
Angular Component InteractionAngular Component Interaction
Angular Component Interaction
 
Chrome 68 updates
Chrome 68 updatesChrome 68 updates
Chrome 68 updates
 
Reactive Programming with Rxjs
Reactive Programming with RxjsReactive Programming with Rxjs
Reactive Programming with Rxjs
 
Angular Features and New Things
Angular Features and New ThingsAngular Features and New Things
Angular Features and New Things
 
Ror 4주차(루비맛보기, form 태그)
Ror 4주차(루비맛보기, form 태그)Ror 4주차(루비맛보기, form 태그)
Ror 4주차(루비맛보기, form 태그)
 
Ror 2주차(컨트롤러 생성)
Ror 2주차(컨트롤러 생성)Ror 2주차(컨트롤러 생성)
Ror 2주차(컨트롤러 생성)
 
루비온레일즈_01_간단한 정적인 홈페이지 제작
루비온레일즈_01_간단한 정적인 홈페이지 제작루비온레일즈_01_간단한 정적인 홈페이지 제작
루비온레일즈_01_간단한 정적인 홈페이지 제작
 
Basic of web ref.웹을지탱하는기술_02
Basic of web ref.웹을지탱하는기술_02Basic of web ref.웹을지탱하는기술_02
Basic of web ref.웹을지탱하는기술_02
 
Eclipse gef
Eclipse gefEclipse gef
Eclipse gef
 
Gef 정리
Gef 정리Gef 정리
Gef 정리
 
Eclipse rcp 정리(enabled when, contextmenu)
Eclipse rcp 정리(enabled when, contextmenu)Eclipse rcp 정리(enabled when, contextmenu)
Eclipse rcp 정리(enabled when, contextmenu)
 
2015.07.01
2015.07.012015.07.01
2015.07.01
 
Basic of web ref.웹을지탱하는기술_01
Basic of web ref.웹을지탱하는기술_01Basic of web ref.웹을지탱하는기술_01
Basic of web ref.웹을지탱하는기술_01
 
Html5 video
Html5 videoHtml5 video
Html5 video
 

[IOS말고 Android] Inflation을 이용하여 부분 Activity 띄우기

  • 1. [IOS말고 ANDROID] Inflation을 이용하여 부분 Activity 띄우기 #inflation #inflater #getSystemService Inflation을 이용하여 부분 Activity 띄우기 lsh00124@naver.com 이상훈
  • 3. @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } MainActivity는 onCreate()에서 이미 메모리상에 올려 놓았다. 따라서 findViewById를 통해 container 레이아웃을 찾을 수 있다.
  • 4. 하지만 sub_layout.xml은 그렇지 않다. 그래서 inflater를 이용하여 우선적으로 메모리상에 올려놔야 나중에 가져올 수 있다. getSystemService를 통해서 시스템 객체를 참 조한다. 이것은 여러 개의 type이 있기 때문에 LayoutInflater로 casting한다.
  • 5. public void button1Clicked(View v){ //MainActivity.java는 'setContentView(R.layout.activity_main)'를 통해서 //메모리에 올렸기 때문에 findViewById를 통해 container 레이아웃을 바로 찾는다. LinearLayout container = (LinearLayout)findViewById(R.id.container); //inflater는 메모리 상에 올려준다. //즉 객체화등을 통해 뷰그룹 같은 것을 사용할 수 있게 해준다. //getSystemService를 통해서 시스템객체를 참조한다. //getSystemService는 여러개의 타입이 있어서 LayoutInflater 타입으로 casting한다. LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); //inflater의 inflate를 통해서 sub_layout을 메모리상에 올리고 container에 붙여준다. inflater.inflate(R.layout.sub_layout, container, true); //sub_layout이 메모리 상에 있기 때문에 이 안에 있는 뷰그룹을 사용할 수 있다. Button button = (Button)findViewById(R.id.button2);//container.findViewById도 됨. button.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { Toast.makeText(getApplicationContext(),"부분화면의 버튼이 눌러졌습니다", Toast.LENGTH_LONG).show(); } });
  • 6. public void button1Clicked(View v){ //MainActivity.java는 'setContentView(R.layout.activity_main)'를 통해서 //메모리에 올렸기 때문에 findViewById를 통해 container 레이아웃을 바로 찾는다. LinearLayout container = (LinearLayout)findViewById(R.id.container); //inflater는 메모리 상에 올려준다. //즉 객체화등을 통해 뷰그룹 같은 것을 사용할 수 있게 해준다. //getSystemService를 통해서 시스템객체를 참조한다. //getSystemService는 여러개의 타입이 있어서 LayoutInflater 타입으로 casting한다. LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); //inflater의 inflate를 통해서 sub_layout을 메모리상에 올리고 container에 붙여준다. inflater.inflate(R.layout.sub_layout, container, true); //sub_layout이 메모리 상에 있기 때문에 이 안에 있는 뷰그룹을 사용할 수 있다. Button button = (Button)findViewById(R.id.button2);//container.findViewById도 됨. button.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { Toast.makeText(getApplicationContext(),"부분화면의 버튼이 눌러졌습니다", Toast.LENGTH_LONG).show(); } }); inflate()를 이용해서 sub_layout을 메모리 상에 올리고 container에 붙여준다. 버튼을 클릭했을때 Toast message를 띄워 주기 위해 sub_layout 상의 버튼을 가져와 야 하는데, 이떄 sub_layout은 inflate()를 통해서 메모리상에 올려 놓았기 때문에 바 로 참조하여 가져올 수 있다. container.findViewById()를 통해 참조를 해야하는데 그냥 findeViewById()를 해도 참조가 된다.
  • 7. activity_main에서 '부분화면 띄우기' 버튼을 클릭하면 container layout 상에 sub_layout이 띄워진다. sub_layout상에는 '부분화면에서 버튼클릭이벤트' 버튼이 있는데 이것을 클릭하면 Toast message가 뜬다.