Android - Custom Icons in ListView

Posted by Ryan on Stack Overflow See other posts from Stack Overflow or by Ryan
Published on 2010-05-28T17:40:33Z Indexed on 2010/05/28 17:41 UTC
Read the original article Hit count: 534

Filed under:
|
|

Is there any way to place a custom icon for each group item? Like for phone I'd like to place a phone, for housing I'd like to place a house. Here is my code, but it keeps throwing a Warning and locks up on me.

ListView myList = (ListView) findViewById(R.id.myList);
                //ExpandableListAdapter adapter = new MyExpandableListAdapter(data);
                List<Map<String, Object>> groupData = new ArrayList<Map<String, Object>>();

                Iterator it = data.entrySet().iterator();
                while (it.hasNext()) 
                {
                    //Get the key name and value for it
                    Map.Entry pair = (Map.Entry)it.next();
                    String keyName = (String) pair.getKey();
                    String value = pair.getValue().toString();

                    //Add the parents -- aka main categories
                    Map<String, Object> curGroupMap = new HashMap<String, Object>();
                    groupData.add(curGroupMap);
                    if (value == "Phone")
                        curGroupMap.put("ICON", findViewById(R.drawable.phone));
                    else if (value == "Housing")
                    curGroupMap.put("NAME", keyName);
                    curGroupMap.put("VALUE", value);


                }

                // Set up our adapter
                mAdapter = new SimpleAdapter(
                        mContext,
                        groupData,
                        R.layout.exp_list_parent,
                        new String[] { "ICON", "NAME", "VALUE" },
                        new int[] { R.id.iconImg, R.id.rowText1, R.id.rowText2  }
                        );

                myList.setAdapter(mAdapter);

The error i'm getting:

05-28 17:36:21.738: WARN/System.err(494): java.io.IOException: Is a directory

05-28 17:36:21.809: WARN/System.err(494): at org.apache.harmony.luni.platform.OSFileSystem.readImpl(Native Method) 05-28 17:36:21.838: WARN/System.err(494): at org.apache.harmony.luni.platform.OSFileSystem.read(OSFileSystem.java:158) 05-28 17:36:21.851: WARN/System.err(494): at java.io.FileInputStream.read(FileInputStream.java:319) 05-28 17:36:21.879: WARN/System.err(494): at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:183) 05-28 17:36:21.908: WARN/System.err(494): at java.io.BufferedInputStream.read(BufferedInputStream.java:346) 05-28 17:36:21.918: WARN/System.err(494): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 05-28 17:36:21.937: WARN/System.err(494): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459) 05-28 17:36:21.948: WARN/System.err(494): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:271) 05-28 17:36:21.958: WARN/System.err(494): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:296) 05-28 17:36:21.978: WARN/System.err(494): at android.graphics.drawable.Drawable.createFromPath(Drawable.java:801) 05-28 17:36:21.988: WARN/System.err(494): at android.widget.ImageView.resolveUri(ImageView.java:501) 05-28 17:36:21.998: WARN/System.err(494): at android.widget.ImageView.setImageURI(ImageView.java:289)

Thanks in advance for your help!!

© Stack Overflow or respective owner

Related posts about android

Related posts about listview