Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 게임개발공모전
- 프로그래머스
- BFS
- 이득우
- UI 자동화
- 너비우선탐색
- fsm
- 웅진씽크빅
- 시리얼라이제이션
- 개발일지
- upper_bound
- 게임개발
- 알고리즘
- 이분탐색
- c#
- 유한상태기계
- binary_search
- 언리얼
- 인프런
- 유니티
- unity
- 안드로이드
- 재귀
- 구현
- 백준
- unreal
- DFS
- lower_bound
- 운영체제
- c++
Archives
- Today
- Total
초고교급 희망
[Android][Java] Activity 코드를 Fragment로 변경하기 본문
728x90
구글링해서 나오는 예제는 Activity가 많은데 졸업 프로젝트를 Fragment로 하게 됐다.
예제의 Activity코드를 내 프로젝트에 Fragment로 옮겨오는 법...

1. onCreate의 내용은 onCreateView에 넣는다.
2. findViewById 앞에 뷰 적기
Activity일 때
button = (Button)findViewById(R.id.button);
Fragment일 때
View myView = inflater.inflate(R.layout.fragment_ocr, container, false);
galleryBtn = (Button)myView.findViewById(R.id.galleryBtn);
3.resultCode를 쓴다면 이것도 앞에 액티비티 적어주기
Activity
resultCode == RESULT_OK
Fragment
resultCode == Activity.RESULT_OK
4. getContentResolver() 앞에도 getActivity()를 적어준다.
getActivity().getContentResolver()
728x90