Android Question Remove duplicate entries in a Map

GMan

Well-Known Member
Licensed User
Longtime User
Hoi,

i have a map, generated and filled with datas from a database.
Some entries are doubled, so i want to delete the "Doubles".

I searched here, but found nothing depending, so any help would be appriciated.
 

GMan

Well-Known Member
Licensed User
Longtime User
Its a virtual map and is filles dynamically when the Datas from the DB are readed.
So several items has the same category which are listed in this map as duplicates.

Now i want to delete the doubles to get a clean map with categories (every shown once)
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
As NJDude said, if you write a key to a map that already exists, the existing one will be overwritten, so there can not be duplicates if the keys are identical. Have you checked for spaces in the keys?
 
Upvote 0

Reviewnow

Active Member
Licensed User
Longtime User
when selecting the information from your db use the group by clause this will remove the duplications

example : Select category from table group by category order by category
 
Upvote 0

GMan

Well-Known Member
Licensed User
Longtime User
i am using this part form the Database Tut:
B4X:
Try
    'Gets all the available screws
    ExecuteRemoteQuery("SELECT kategorie, id FROM screwtable ORDER BY id", SCREW_LIST)
    Catch As Exception
        ToastMessageShow("Internet needed", True)
End Try

This is the Query:
B4X:
Sub ExecuteRemoteQuery(Query As String, JobName As String)
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.PostString("http://www.xxx.xx/m/db/screws.php", Query)
End Sub

So i think, in the JobDone sub the correct code is missing:
B4X:
Sub JobDone(Job As HttpJob)
ProgressDialogHide
    If Job.Success Then

        Dim res As String
        res = Job.GetString
        Log("Response from server: " & res)

Dim parser As JSONParser
        parser.Initialize(res)
        Select Job.JobName
        
            Case SCREW_LIST
                Dim SCREWNAMES As List
                SCREWNAMES= parser.NextArray 'returns a list with maps
            

            
                For i = 0 To SCREWNAMES.Size - 1
                    Dim m As Map
                    Dim mm As Map
                    m = SCREWNAMES.Get(i)
                    mm = SCREWNAMES.Get(i)
                 
                    Dim tl As TwoLines

                    tl.First = m.Get("kategorie")
                    sm.AddItem(tl.first, LoadBitmap(File.DirAssets, "book_open.png"), tl.First)
                
                    tl.Second = m.Get("name")
                    clv3.Add(CreateListItem(tl.Second, clv3.AsView.Width, 50dip), 50dip, tl)
    Next

...
etc.

the mm - part is what brings the entries to the map (this map is displayed as content in a SlideMenu) - but with duplicates (as far i can see)
 
Last edited:
Upvote 0
Top