안드로이드 개발 질문/답변
(글 수 45,052)
이클립스 최신버젼과 안드로이드 1.5 r(3) 를 사용하고있습니다 .
최근 안드로이드를 보면서 일단 홈페이지 예제를 노트패드 까지 구현해볼려고 하나 하나 연습하고 있습니다 .
그러던중 http://developer.android.com/guide/tutorials/views/hello-gallery.html 예제를 연습하고있는데 .
문제가 생겼어요
obtainStyledAttributes(android.R.styleable.Theme);
이부분에서 에러가 납니다 .
android.R.styleable 가 없고 android.R.style.Theme 만가능하더군요
제가 사용을 잘못한것인지
obtainStyledAttributes의 사용법을 알고 싶습니다 .
// TypedArray a = obtainStyledAttributes(android.R.styleable.Theme);
// mGalleryItemBackground = a.getResourceId(
// android.R.styleable.Theme_galleryItemBackground, 0);
// a.recycle();
이부분을 주석처리하면 구동은 되더군요 .
하지만 테마가 적용안되어서 보이는게 안습
너무 초보적인 질문이긴하지만 도와주세요 .. ㅜ_ㅜ
참고로 apiDemo 의 gallery1 의 경우에는 잘되는데 제가 안되는게 무슨문제가 있는건지 ㅠ_ㅠ
arry.xml 까지 복사해서 고쳐주었는데 ㅠ_ㅠ
고쳐주니 R.styleable 는되는데 obtainStyledAttributes이게문제 ....
소스첨부했습니다 .
여기저기 검색해봐도 답을 모르겠네요 .
2009.09.09 22:40:04
그건 이미 arry.xml 파일을 복사해와서 수정해주었지요 .
위에건 안드로이드 홈페이지 원문소스 입니다 .
주석처리하면 되긴된다는....
실제 바꾸어서 테스트 해보면 obtainStyledAttributes 이게 안된다고 나옵니다 ..
2009.09.10 10:27:32
귀찮아서 소스를 안받아봤더니 헛소리를 했군요... 죄송합니다...
public ImageAdapter(Context c) {
mContext = c;
// TypedArray a = obtainStyledAttributes(R.styleable.Gallery01);
TypedArray a = ((Activity) c).obtainStyledAttributes(R.styleable.Gallery01);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery01_android_galleryItemBackground, 0);
a.recycle();
}
obtainStyledAttributes() 요 메서드가 액티비티에 있는건가보군요...
Context 캐스팅해서 사용하니 잘되네요...
ImageAdapter를 소스를 분리하셔서... Apidemos처럼 작동 안됐나보군요..
public ImageAdapter(Context c) {
mContext = c;
// TypedArray a = obtainStyledAttributes(R.styleable.Gallery01);
TypedArray a = ((Activity) c).obtainStyledAttributes(R.styleable.Gallery01);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery01_android_galleryItemBackground, 0);
a.recycle();
}
obtainStyledAttributes() 요 메서드가 액티비티에 있는건가보군요...
Context 캐스팅해서 사용하니 잘되네요...
ImageAdapter를 소스를 분리하셔서... Apidemos처럼 작동 안됐나보군요..
android.R이 아니라 R로 되있네요
values/attrs.xml에 선언되 되있네요...
76 public ImageAdapter(Context c) {
77 mContext = c;
78 // See res/values/attrs.xml for the <declare-styleable> that defines
79 // Gallery1.
80 TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
81 mGalleryItemBackground = a.getResourceId(
82 R.styleable.Gallery1_android_galleryItemBackground, 0);
83 a.recycle();
84 }