본문 바로가기

개발도구/aOS - 안드로이드 개발

[안드로이드] 다른 클래스에서 액티비티 갖고 와서 사용하기 inflate

LayoutInflater 을 이용하면 다른 layout 에 있는 액티비티를 갖다 현재 클래스에서 사용이 가능하다.

drawer.class, drawer.xml 에 
ImageButton navi_next 가 있다.

Intro.class 에서 drawer.xml 에 navi_next 이미지 버튼을 갖고 오려 한다. 
그러할때 아래와 같이 사용 하면 쉽게 갖고 올수가 있다. 

----------------------------------------------------------------------

private ImageButton navi_next;
private View header;
private LayoutInflater inflater;
 
inflater = getLayoutInflater();
header = inflater.inflate(R.layout.drawer, null);
if(header != null){
       Log.v("00", "00");
}
navi_next  = (ImageButton)header.findViewById(R.id.navi_next);
navi_next.setBackgroundResource(R.drawable.navi_next_off);

----------------------------------------------------------------------

단  Intro.xml 에
<co.kr.test.apis.Drawer
    android:id = "@+id/customDrawer"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_gravity="bottom" 
    />
    
이렇게 클래스로 호출된 것은 Inflater 을 해도 소용이 없다.
그러할때는
draw = (Drawer)findViewById(R.id.customDrawer);
navi_next = (ImageButton)draw.findViewById(R.id.navi_next);
이렇게 R.layout. 으로 여겨서 사용하면 된다. 
 
난 이것때문에 3-4 시간을 헤멧다..
이젠 초금을 졸업했거니 생각했었는데, 아직도 큰 그림을 그리지 못한다.
휴=33 많이 좋아지겠지.. ㅠ