예제 보면서 우걱우걱 끼워맞추고 있는데, findViewById 에서 null 이 리턴되네요.

XML 에도 제대로 선언되어 있고, 처음보는 문제라 좀 당황하면서 찾아봤습니다.

일단 setContentView 를 하는 상황에서는 문제가 없고, Dialog 에 넣을 custom layout 을 사용하는 상황에서만 문제가 있더라구요.

아마 저같은 경우 button 의 onClick 이벤트 받는 곳에서 다이얼로그를 띄우려고 하니 이 this 가 그 this 가 아니었나봐요~ 응?


결론은 아래 붉은색 부분과 같이 inflate 한 View 에서 findViewById 를 호출해야 한다는 것입니다.


Context mContext = getApplicationContext();

LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);

View removeLayout = inflater.inflate(R.layout.remove_dialog_content,null);

ImageView removeImage = (ImageView)removeLayout.findViewById(R.id.removeImg);

removeImage.setBackgroundDrawable(toRemoveSlide);


그럼 다시 우걱우걱~

 
블로그 이미지

AP4ILL

Time just fades the pages in my book of memories..

카테고리

분류 전체보기 (198)
2012년 이전 (165)
2013년 (25)
2014년 (7)