由网友(辜负孤独)分享简介:我想显示这样的任务列表 - I am trying to display a list of task in this way - 图标|应用程序名称|复选框Icon | ApplicationName | CheckBox因为我发现没有任何的ListView适配器支持这个,所以我决定开发一个定制的适配器,但...
我想显示这样的任务列表 -
I am trying to display a list of task in this way -
图标|应用程序名称|复选框
Icon | ApplicationName | CheckBox
因为我发现没有任何的ListView适配器支持这个,所以我决定开发一个定制的适配器,但我无法获取应用程序的图标。到目前为止,我想这: -
As i found that no listview adapter supports this so i decided to develop a custom adapter but i am unable to fetch the icon of an application. So far i tried this :-
public View getView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
View row = inflater.inflate(R.layout.item, parent, false);
CheckedTextView ctb = (CheckedTextView)row.findViewById(R.id.checkText);
String pkgName = "com.abc.abc";
ctb.setText("bla bla");
ImageView iv = (ImageView)row.findViewById(R.id.image);
List<PackageInfo> pkgs = activity.getPackageManager().getInstalledPackages(0);
for(PackageInfo p : pkgs)
{
if(p.packageName.equals(pkgName))
{
Drawable d = p.applicationInfo.loadIcon(pm);
iv.setImageDrawable(d);
}
}
return row;
}
}
,我相信我试图在这个code一些愚蠢的事。请尽量赶上无论我做错了。
And i am sure i am trying something stupid in this code. Please try to catch whatever i am doing wrong.
感谢。
推荐答案
您可以得到一个应用程序的(包的)图标用:
You can get an app's (package's) icon with:
String pkg = "com.app.my";
Drawable icon = getContext().getPackageManager().getApplicationIcon(pkg);
相关推荐
最新文章