是否可以为每个组项目放置自定义图标?像是电话,我想放置电话,而房屋,我想放置房屋。这是我的代码,但是它不断抛出警告并锁定我。

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

                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);
                    Log.i("VAL", keyName);
                    if (keyName.equalsIgnoreCase("Phone"))
                        curGroupMap.put("ICON", findViewById(R.drawable.phone_icon));
                    else if (keyName.equalsIgnoreCase("Housing"))
                        curGroupMap.put("ICON", findViewById(R.drawable.house_icon));
                    else
                        curGroupMap.put("ICON", findViewById(R.drawable.house_icon));

                    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.photoAlbumImg, R.id.rowText1, R.id.rowText2  }
                        );

                myList.setAdapter(mAdapter);


我得到的错误:

    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)


在此先感谢您的帮助!!

最佳答案

if (value == "Phone")


您需要使用equals比较字符串。因此,很可能永远不会执行用于设置可绘制对象的代码,然后simpleadapter尝试将字符串作为文件加载,并且出现奇怪的错误。

09-29 22:51