查看文章 |
解决 Android 提供的 HelloGallery 例子编译不过的问题
2009-07-06 16:14
HelloWorld, HelloForm, HelloListView, ... , 完成了前面 N 个 HelloXXX, 今天终于来到 HelloGallery 了, 但 google 提供的例子 HelloGallery 居然不能通过编译. 问题症状是: 编译器发出 android.R.styleable 不能找到的错误. (android.R.styleable cannot be resolved) 我到网上查了查, 有不少人都碰到了这个错误, 可无论是 Android Beginner Group 还是 xda forum 都没有提供解决方法(报怨的人倒是不少). 咋办? 决定还是从其它网站提供的例子入手, 找了半天, 终于在 http://www.eoeandroid.com/viewthread.php?tid=479 找到一个 gallery 的例子, 分析了这个例子后, 终于解决了 HelloGallery 的编译问题. 执行下面操作就可正常编译通过和运行: 第1步. append file attars.xml in res/values with content: <resources> <declare-styleable name="Gallery"> <attr name="android:galleryItemBackground"> </attr> </declare-styleable> </resources> 第2步. modify the code from public ImageAdapter(Context c) { mContext = c; TypedArray a = obtainStyledAttributes(android.R.styleable.Theme); mGalleryItemBackground = a.getResourceId( android.R.styleable.Theme_galleryItemBackground, 0); a.recycle(); } to public ImageAdapter(Context c) { mContext = c; TypedArray a = obtainStyledAttributes(R.styleable.Gallery); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery_android_galleryItemBackground, 0); a.recycle(); } 然后再 re-build HelloGallery, 问题解决! |
最近读者:

