如何将从结果中获得的应用程序图标获取到数组列表中?
如果我使用
attrs.icon("包名称", pkg.applicationInfo.loadIcon(getPackageManager()));
显示此错误 Map 类型未定义方法 icon(String, Drawable)
如果我使用
attrs.put("包名称", pkg.applicationInfo.loadIcon(getPackageManager()));
显示此错误 Map 类型中的 put(String, String) 方法不适用于参数 (String, Drawable)
我已经尝试过
可绘制图标;
attrs.icon("包名称", pkg.applicationInfo.loadIcon(getPackageManager()));
可绘制图标 = 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;
}
}
最佳答案
attrs
是一个 Map,因此它没有名为“icon”的方法。您只需执行 attrs.put("icon",pkg.applicationInfo.icon+"");
+""
之所以存在,是因为 pkg.applicationInfo.icon 是一个整数,因此您需要将其转换为字符串,然后才能将其放入使用
关于java - 如何将包图标添加到数组列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8376174/