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:


December 12th, 2008 at 5:52 pm
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.
December 12th, 2008 at 5:57 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.
December 14th, 2008 at 3:46 am
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?
January 30th, 2009 at 2:26 am
Michael,
Great post. I came across your blog looking for help with drawables and found your blogs. Really interesting, keep them coming!
Darren
February 22nd, 2009 at 3:11 pm
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
March 20th, 2009 at 2:59 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
March 20th, 2009 at 4:15 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 :).
March 21st, 2009 at 3:13 am
Cheers …
February 20th, 2010 at 1:07 am
[…] Listing Androids drawable Resources […]
March 16th, 2010 at 10:39 am
very nice app. Thank you, good sir!
April 2nd, 2010 at 2:50 pm
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
April 23rd, 2010 at 8:53 am
big up!