Android Question [B4X] Treeview Structure with For Each

Discussion in 'Android Questions' started by Alexander Stolte, May 16, 2019.

  1. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    Hey, this question is a general programming question.

    My goal is a Treeview Structure.
    I have the following Database Structure: id and parent_id
    upload_2019-5-16_10-14-11.png
    If parent_id = 0 Then it is a root item.

    My considerations were a For Each loop

    This is just pseudo code:
    Code:
    For Each id in table

    If parent_id = 0 then

    add item 
    to list

    For Each parent_id In id

    if id = parent_id then

    add item 
    to second level

    end if

    NExt

    End if

    Next
    How would you solve such an assignment?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Are you asking about the UI implementation or about the data structure?

    The data structure should be based on a custom type such as this one:
    Code:
    Type TreeElement (Children As List, Value As Object, Parent As TreeElement)
    Each element in the Children list is a TreeElement type.
     
    José J. Aguilar likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice