Android - 列出列表中的应用程序图标并运行选定的
我正在 eclipse 中开发 Android 应用程序。
我有一个显示已安装应用程序的列表,列表如下:
//Listar apps instaladas
final ListView list1 = (ListView) findViewById(R.id.list1);
ArrayList results = new ArrayList();
PackageManager pm = this.getPackageManager();
Intent inte = new Intent(Intent.ACTION_MAIN, null);
inte.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> list = pm.queryIntentActivities(inte, PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
}
list1.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, results));
我的问题是: 我怎样才能做到这一点而不是显示图标名称?如果我这样做,
results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
它会显示“android.graphics.drawable @应用程序的名称” 我该如何通过单击列表来运行应用程序?我尝试了几次,但应用程序出错了。 谢谢!
Im developing an Android app in eclipse.
I have a list showing the applications installed, the list is this:
//Listar apps instaladas
final ListView list1 = (ListView) findViewById(R.id.list1);
ArrayList results = new ArrayList();
PackageManager pm = this.getPackageManager();
Intent inte = new Intent(Intent.ACTION_MAIN, null);
inte.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> list = pm.queryIntentActivities(inte, PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
}
list1.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, results));
My questions are:
How I can do that instead of showing the icons name? if I do it
results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
show me "android.graphics.drawable @ name of the application"
And how I can do to run the application by clicking on the list? I tried several attempts, but I make the application error.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
通过这行代码,我假设您正在加载应用程序的标签,所以也许您应该尝试 loadName 或其他东西,检查您可以在那里选择什么,因为我自己以前没有这样做过。
当你点击列表时你会得到什么错误?这也会有帮助:)
results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
with this line of code I assume you're loading the label of the application, so perhaps you should try loadName or something, check what you can pick there anyway since I haven't done this myself before.
And which error do you get when you click the list? this would be helpful too :)