如何将包图标添加到arraylist中

时间:2011-12-04 15:05:37

标签: java android arraylist

如何将我从结果中获得的应用程序图标转换为arraylist?

如果我使用 attrs.icon("Package Name", pkg.applicationInfo.loadIcon(getPackageManager()));

它显示此错误 方法图标(String,Drawable)未定义类型Map

如果我使用 attrs.put("Package Name", pkg.applicationInfo.loadIcon(getPackageManager()));

它显示此错误 方法中的put(String,String)方法不适用于参数(String,Drawable)

我试过

Drawable icon;

attrs.icon("Package Name", pkg.applicationInfo.loadIcon(getPackageManager()));

Drawable Icon = pm.getApplicationIcon(pkg.applicationInfo);

所有在eclipse上给出错误

这是代码

protected void onPostExecute(List < PackageInfo > result) {

    // Here you will have all the setAdapter related code
    List < PackageInfo > adPackages = result;
    PackageManager pm = getPackageManager();

    List < Map < String, String >> data = new ArrayList < Map < String, String >> (
    adPackages.size());

    for (PackageInfo pkg: adPackages) {
        Map < String, String > attrs = new HashMap < String, String > ();

        attrs.put("App Name", pm.getApplicationLabel(pkg.applicationInfo).toString());
        attrs.put("Package Name", pkg.packageName);
        //Drawable icon;
        //attrs.icon("Package Name", pkg.applicationInfo.loadIcon(getPackageManager()));
        // Drawable Icon = pm.getApplicationIcon(pkg.applicationInfo);
        data.add(attrs);

    }

    String[] from = new String[] {
        "App Name", "Package Name"
    };
    int[] to = new int[] {
        R.id.text1, R.id.text2
    };
    SimpleAdapter adapter = new SimpleAdapter(
    AppsInspectorActivity.this, data, R.layout.two_line_list_item, from, to);

    ListView mList = (ListView) findViewById(R.id.l_list);

    mList.setAdapter(adapter);
    mPackages = adPackages;

}
}

1 个答案:

答案 0 :(得分:1)

attrs是一张地图,因此它没有名为“icon”的方法。你需要做attrs.put("icon",pkg.applicationInfo.icon+""); +""是因为pkg.applicationInfo.icon是一个整数,所以你需要将它转换为String,然后才能将它放入参数化的地图中