PackageManager sort

anaylor01

Well-Known Member
Licensed User
Longtime User
I was able to get the labels and sort them but as far as creating the map and then creating a relationship no go.

B4X:
Sub PopulateList
Dim packages, packagessort As List
Dim bt(500) As BitmapDrawable
listview1.Visible = True
Dim map1 As Map
packages = pm.GetInstalledPackages
packagessort.Initialize
For i = 0 To packages.Size - 1
    packagessort.Add(pm.GetApplicationLabel(packages.Get(i)))
Next 
packagessort.Sort(True)
For i = 0 To packagessort.Size - 1
    'bt(i) = pm.GetApplicationIcon(packages.get(i))
    'listview1.AddTwoLinesAndBitmap2(pm.GetApplicationLabel(packages.Get(i)),"",bt(i).Bitmap,packages.Get(i))
    listview1.AddSingleLine(packagessort.Get(i))
Next
map1.Initialize
Dim items As String
Dim icns As BitmapDrawable
For i = 0 To packages.Size - 1 
    items = packages.Get(i)
    bt(i) = pm.GetApplicationIcon(packages.get(i))
    Map1.put(packages.Get(i),Items(0))
    Map1.put(bt(i).Bitmap)
Next

End Sub
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Look at the order of things Erel gave you:

Create a map and a list
Add all the packages names to the list.
Add all the names and icons to the map.
Sort the list.
Go over all the items (names) in the list and grab the icon from the map.
Not:

Create a map and a list.
Add all the packages names to the list.
Sort the list.
Add all the names and icons to the map.

that you appear to have done.
 
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
What I was trying to do was do them separately and then combine them. So what I did was create the list of package labels and then sorted them. That worked. I know that the idea is to use the index of the packages before sort to link the list and the map together but I couldn't get the map part to work.
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
You have missed
Go over all the items (names) in the list and grab the icon from the map.

B4X:
    Map1.put(packages.Get(i),Items(0))
    Map1..put(bt(i).Bitmap)
is wrong, have a look at the help for maps and how to add a key/value pair.

Also it is the package label not the name that needs to be the map key

I could write the code for you but I think you will learn more if you investigate how to do things yourself.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…