0

从这段代码开始

class PackageInfoData{
    private String appname = "";
    private String pname = "";
    private String versionName = "";
    private int versionCode = 0;
    private Drawable icon;
}

private void getInstalledPackages() {
    ArrayList<PackageInfoData> installedApps = getInstalledApps(false); /* false = no system packages */
    for (int i=0; i<installedApps.size(); i++) {
       Log.i("Instlled app","APp Name:"+installedApps.get(i).appname+"package:"+installedApps.get(i).pname);
    }
    return installedApps ;
}

private ArrayList<PackageInfoData> getInstalledApps(boolean getSysPackages) {
    ArrayList<PackageInfoData> res = new ArrayList<PackageInfoData>();        
    List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
    for(int i=0;i<packs.size();i++) {
        PackageInfo p = packs.get(i);
        if ((!getSysPackages) && (p.versionName == null)) {
            continue ;
        }
        PackageInfoDatanewInfo = new PackageInfoData();
        newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
        newInfo.pname = p.packageName;
        newInfo.versionName = p.versionName;
        newInfo.versionCode = p.versionCode;
        newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
        res.add(newInfo);
    }
    return res; 
}

这将返回设备中安装的应用程序列表,我希望该列表是可折叠的。例如,我有一个按钮,当我单击它时,列表将出现,当我再次单击按钮时,列表消失。我该怎么做?

4

0 回答 0