안드로이드 개발 질문/답변
(글 수 45,052)
Dialog 안에서 Spinner 를 구현 할 수 있는 방법이 있는지 알고싶습니다.
일반적인 방법으로 Dialog 안에 Spinner 를 넣으면 일단 화면은 나오지만
Spinner를 클릭했을 때
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
이 에러가 나면서 강제종료 되는데요...
혹시 가능한 방법이 있을까 해서 질문 올려봅니다.
제가 일반적인 방법이라고 한것은 Spinner가 들어있는 Xml Layout을
LayoutInflater 를 이용해 Custom Dialog를 만든것을 얘기합니다.
Custom Dialog 생성 과정에서
Spinner mFontSizeSpinner = (Spinner)mFontLayout.findViewById(R.id.Font_Size_Spinner);
mAdapter = ArrayAdapter.createFromResource(this, R.array.size_array, android.R.layout.simple_spinner_item);
mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mFontSizeSpinner.setAdapter(mAdapter);
이런식으로 Spinner에 들어갈 목록을 설정하였습니다.
일반적인 방법으로 Dialog 안에 Spinner 를 넣으면 일단 화면은 나오지만
Spinner를 클릭했을 때
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
이 에러가 나면서 강제종료 되는데요...
혹시 가능한 방법이 있을까 해서 질문 올려봅니다.
제가 일반적인 방법이라고 한것은 Spinner가 들어있는 Xml Layout을
LayoutInflater 를 이용해 Custom Dialog를 만든것을 얘기합니다.
Custom Dialog 생성 과정에서
Spinner mFontSizeSpinner = (Spinner)mFontLayout.findViewById(R.id.Font_Size_Spinner);
mAdapter = ArrayAdapter.createFromResource(this, R.array.size_array, android.R.layout.simple_spinner_item);
mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mFontSizeSpinner.setAdapter(mAdapter);
이런식으로 Spinner에 들어갈 목록을 설정하였습니다.
2010.06.09 19:20:49
나중에 이 질문내용을 참조 하시는분이 있을수도 있어서 내용 하나 남깁니다.
LayoutInflater를 이용하여 Custom Dialog를 만들때
LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
이 메소드 앞에서 mContext 값을 받아오는 부분을
Layout에 Spinner 가 없는 경우에는 developer 사이트에 있는대로
Context mContext = getApplicationContext(); 그대로 쓰시면 되고
Layout에 Spinner 가 있는 경우에는
Context mContext = 현재 Activity를 상속받은 java파일의 이름 .this;
이렇게 하지 않으면 에러가 나는군요.
참조하세요 ^^
LayoutInflater를 이용하여 Custom Dialog를 만들때
LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
이 메소드 앞에서 mContext 값을 받아오는 부분을
Layout에 Spinner 가 없는 경우에는 developer 사이트에 있는대로
Context mContext = getApplicationContext(); 그대로 쓰시면 되고
Layout에 Spinner 가 있는 경우에는
Context mContext = 현재 Activity를 상속받은 java파일의 이름 .this;
이렇게 하지 않으면 에러가 나는군요.
참조하세요 ^^
혹시 getApplicationContext()를 하여서 나온 컨텍스트를 사용했나요?
비슷한 에러를 본 기억이 있어서요 :)