我将数据库值与packageinfo进行比较,这是截图http://imgur.com/psGyBGo
我获取列表中的所有数据库值列表arraylist = db.getAllApps();
如何将此列表与安装ap包名称列表进行比较?下面是我的代码快照PLZ帮我怎么比较???此行不是过滤值 if((p.packageName).equals(arraylist))如何过滤值匹配并仅显示列表中与数据库匹配的值
private List<App> loadInstalledApps(boolean includeSysApps) {
List<App> apps = new ArrayList<App>();
// the package manager contains the information about all installed apps
PackageManager packageManager = getPackageManager();
List<PackageInfo> packs = packageManager.getInstalledPackages(0);
List arraylist = db.getAllApps();
for (int i = 0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
ApplicationInfo applicationInfo = p.applicationInfo;
// if (arraylist.equals(p.packageName))
if ( (p.packageName).equals(arraylist))
{
App app = new App();
app.setTitle(p.applicationInfo.loadLabel(packageManager)
.toString());
app.setPackageName(p.packageName);
app.setVersionName(p.versionName);
app.setVersionCode(p.versionCode);
CharSequence description = p.applicationInfo
.loadDescription(packageManager);
app.setDescription(description != null ?
description.toString()
: "");
apps.add(app);
// }
}
}
return apps;
}
答案 0 :(得分:3)
在列表中找到
if(arraylist.contains(p.packageName)) {
//your code here
}
如果arrayList是字符串列表,则此代码有效,如果是其他类,则有两个选项
1)比较所有对象
if(arraylist.contains(p)) {
//your code here
}
2)通过packageName(或其他属性)进行比较
bool isInList = false;
for (MyClass object : array list) {
if (object.packageName.equals(p.packageName)) {
isInList = true;
break;
}
}
if (isInList) {
//your code here
}
答案 1 :(得分:1)
如果您想查看packageName
是否在packageInfo
列表中,那么最简单的方法就是将packageName
与{{1}进行比较你的arraylist中的每个packageName
我假设您的packageInfo
方法有效,因为我不知道PackageInfo对象是什么
.equals()