Android Question Displaying a table using a Spinner

red30

Well-Known Member
Licensed User
Longtime User
I have a table:
table.png
I has several elements: Mark, Model, Generation.
For the example I draw only several elements, but in real there would be about 1000 el.
I want to make three spinners and add a make of the auto to the first. After the make is chosen (fe BMW), in the second there must be corresponding models (i3, i8 according to the table). Then I choose a model and in the third there must be generations also corresponding to the make and model (1 and 1restyling). How can i do this?
 

Attachments

  • test table.zip
    6.8 KB · Views: 222
Last edited:

red30

Well-Known Member
Licensed User
Longtime User
I'm afraid that your question is a bit too broad. There are many ways to do it. The most robust way is to add the data to a SQL table and then you will be able to easily extract the values based on the selection.
Erel, could you show me an exaple with my table? Thank you much in advance!
 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
I did it with the help of the library Excel
B4X:
#Region  Project Attributes
    #ApplicationLabel: Excel Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
End Sub

Sub Globals
    Private Spinner1 As Spinner
    Private Spinner2 As Spinner
    Private Spinner3 As Spinner
    Private spin1,spin2,spin3 As String
    Dim workbook1 As ReadableWorkbook
    Dim moviesSheet As ReadableSheet
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    My(File.DirAssets, "temp.xls")
End Sub

Sub My (Dir As String, FileName As String)
    workbook1.Initialize(Dir, FileName)
    moviesSheet = workbook1.GetSheet(0)
    For i=1 To moviesSheet.RowsCount - 1
        If moviesSheet.GetCellValue(0,i)<>moviesSheet.GetCellValue(0,i-1) Then
            Spinner1.Add(moviesSheet.GetCellValue(0,i))
        End If
    Next
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Spinner1_ItemClick (Position As Int, Value As Object)
    spin1=Value
    For i=1 To moviesSheet.RowsCount - 1
        If moviesSheet.GetCellValue(0,i)=Value And moviesSheet.GetCellValue(1,i)<>moviesSheet.GetCellValue(1,i-1) Then
            Spinner2.Add(moviesSheet.GetCellValue(1,i))
        End If
    Next
End Sub

Sub Spinner2_ItemClick (Position As Int, Value As Object)
    spin2=Value
    For i=1 To moviesSheet.RowsCount - 1
        If moviesSheet.GetCellValue(0,i)=spin1 And moviesSheet.GetCellValue(1,i)=Value And moviesSheet.GetCellValue(2,i)<>moviesSheet.GetCellValue(2,i-1) Then
            Spinner3.Add(moviesSheet.GetCellValue(2,i))
        End If
    Next
End Sub

Sub Spinner3_ItemClick (Position As Int, Value As Object)
    spin3=Value
End Sub
 
Upvote 0
Top