Listing Androids drawable Resources
Wrote this real quick Android ListActivity to display the Resources from the android.R.drawable. Not very pretty, but I just wanted something to display the images and show the associated Resource id. Sorry in advance for any wacky formatting issues due to cutting and pasting from Eclipse into the WordPress editor.
ResourceExplorer.java
public class ResourceExplorer extends ListActivity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// define the list which holds the information of the list
List<Map<String, Object>> resourceNames =
new ArrayList<Map<String, Object>>();
// define the map which will hold the information for each row
Map<String, Object> data;
// hard coded numbers retrieved from
// http://code.google.com/android/reference/android/R.drawable.html
for ( int idx = 17301504; idx <= 17301655; idx++ )
{
data = new HashMap<String, Object>();
try
{
String stg = Resources.getSystem().getResourceName(idx);
data.put("line1", stg );
data.put("line2", idx );
data.put("img", idx );
resourceNames.add(data);
}
catch (Resources.NotFoundException nfe )
{
// noop ignore
}
}
SimpleAdapter notes = new SimpleAdapter(
this,
resourceNames,
R.layout.row,
new String[] { "line1","line2", "img" },
new int[] { R.id.text1, R.id.text2, R.id.img } );
setListAdapter(notes);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
<TextView
android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No data"/>
</LinearLayout>
row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/vw1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="@+id/text1"
android:textSize="12sp"
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/text2"
android:textSize="12sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
When I run this in the emulator I get something that looks like the following:

Very cool and helpful.
I am wondering if google sees this as part of their public API?! It would be great to just use those icons.
Comment by Mariano Kamp — December 12, 2008 @ 5:52 pm
Mariano,
The whole reason to do this was because I wanted to use the ic_menu_preferences icon in my next version of Jumpy. It is fairly simple to then integrate it into the menu bar using
<item android:id=”@+id/settings_menu_item”
android:title=”@string/settings_menu_label”
android:alphabeticShortcut=”@string/settings_menu_shortcut”
android:icon=”@android:drawable/ic_menu_preferences” />
I hope to be writing a blog post on this soon. Got some good pointers out of the yet to be released version of “Hello, Android” by Ed Burnette on building menus using an xml resource file.
Comment by michael — December 12, 2008 @ 5:57 pm
I understand and I was also looking for just that icon for the same reason (I just a less sophisticated approach though: find).
Anyway, my point was, after having found the icons, does Google allow you (well, everyone) to use them? Will they change?
Comment by Mariano Kamp — December 14, 2008 @ 3:46 am
Michael,
Great post. I came across your blog looking for help with drawables and found your blogs. Really interesting, keep them coming!
Darren
Comment by Darren Steele — January 30, 2009 @ 2:26 am
Not to negate this good work of yours, but someone has posted a similarly useful chart of all drawables in the android.R.drawables package here:
http://www.screaming-penguin.com/info/android_drawables/android_drawables.html
Comment by ty — February 22, 2009 @ 3:11 pm
(a) Answering my own question from above. Yes, meanwhile I believe Google sees those as part of the public API.
(b) Dianne, an Android engineer, considers your code useful and suggests to use it in the demos or something like that. See for yourself: http://groups.google.com/group/android-developers/browse_thread/thread/a2fdf66cb6ac865a
Comment by Mariano Kamp — March 20, 2009 @ 2:59 pm
Hey Mariano,
Wow, that’s cool! Thanks for pointing to my site in the Dev Forum…I’ll have to make sure my ego doesn’t get to big! That certainly puts a nice cap on my Friday, I think I’ll go grab a beer :).
Comment by michael — March 20, 2009 @ 4:15 pm
Cheers …
Comment by Mariano Kamp — March 21, 2009 @ 3:13 am
[…] Listing Androids drawable Resources […]
Pingback by » android.R.drawable Icon Resources aquarium — February 20, 2010 @ 1:07 am
very nice app. Thank you, good sir!
Comment by Per Sandström — March 16, 2010 @ 10:39 am
Wow, that is quite brilliant!
Thanks for sharing this.
Couldn’t find a listing of already available drawable ressources in android.
Should be included within the sdk if you ask me
Comment by yci — April 2, 2010 @ 2:50 pm
big up!
Comment by maceo — April 23, 2010 @ 8:53 am