Android
Android] Inflate
김코식
2022. 6. 12. 21:15
Inflate - xml의 레이아웃들을 메모리에 객체화 (xml 코드를 객체화하여 사용)
일반적인 xml객체화 - setContentView() 함수를 사용하여 자동으로 xml 객체화
ex)
protected void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
setContentView(R.layout.activity_Main);
}
setContentView() 함수를 통해 xml에서 지정해놓은 UI요소 사용가능
ex)
Button button = findViewById(R.id.button);
ImageView imageView = findViewById(R.id.imagView);
여러 화면을 한 화면에 구성하거나 Fragment 사용 등의 경우에는 setContentView() 함수를 사용하지 못하기 때문에
직접 객체화를 시켜야한다.
ex) Fragment에서 Inflate
public View onCreateView(LayoutInflater inflater, ViewGroup container , Bundle savedInstanceState){
return inflater.inflate( R.layout.activity_frag,container, false );
}