首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

加载全部自带的图片

2012-09-10 
加载所有自带的图片public class DrawablePreviewActivity extends ListActivity?{?? ? private static fi

加载所有自带的图片

public class DrawablePreviewActivity extends ListActivity?
{?
? ? private static final String TAG = "DrawablePreviewActivity";?
?
? ? public void onCreate(Bundle savedInstanceState)?
? ? {?
? ? ? ? super.onCreate(savedInstanceState);?
?
? ? ? ? setTitle("Preview of android.R.drawable.*");?
?
? ? ? ? try {?
? ? ? ? ? ? Class RClass = Class.forName("android.R");?
?
? ? ? ? ? ? Class[] subclasses = RClass.getDeclaredClasses();?
?
? ? ? ? ? ? Class RDrawable = null;?
?
? ? ? ? ? ? for(Class subclass : subclasses) {?
? ? ? ? ? ? ? ? if("android.R.drawable".equals(subclass.getCanonicalName())) {?
? ? ? ? ? ? ? ? ? ? RDrawable = subclass;?
? ? ? ? ? ? ? ? ? ? break;?
? ? ? ? ? ? ? ? }?
? ? ? ? ? ? }?
?
? ? ? ? ? ? List<Map<String, Object>> drinfo = new ArrayList<Map<String, Object>>();?
?
? ? ? ? ? ? Field[] drawables = RDrawable.getFields();?
? ? ? ? ? ? for(Field dr : drawables) {?
? ? ? ? ? ? ? ? Map<String, Object> map = new HashMap<String, Object>();?
? ? ? ? ? ? ? ? Drawable img = getResources().getDrawable(dr.getInt(null));?
?
? ? ? ? ? ? ? ? map.put("drimg", dr.getInt(null));?
? ? ? ? ? ? ? ? map.put("drname", dr.getName());?
?
? ? ? ? ? ? ? ? drinfo.add(map);?
? ? ? ? ? ? }?
?
? ? ? ? ? ? setListAdapter(new SimpleAdapter(this,?
? ? ? ? ? ? ? ? ? ? ? ? ? ? drinfo,?
? ? ? ? ? ? ? ? ? ? ? ? ? ? R.layout.listitem,?
? ? ? ? ? ? ? ? ? ? ? ? ? ? new String[] { "drimg", "drname" },?
? ? ? ? ? ? ? ? ? ? ? ? ? ? new int[] { R.id.drimg, R.id.drname }));?
?
? ? ? ? } catch(IllegalAccessException iae) {?
? ? ? ? ? ? Log.e(TAG, iae.toString());?
? ? ? ? } catch(ClassNotFoundException cnfe) {?
? ? ? ? ? ? Log.e(TAG, cnfe.toString());?
? ? ? ? }?
? ? }?
}?
源码下载

http://www.altcanvas.com/downloads/drawablepreview.tar.gz

热点排行