Android Question How to Load Layout in landscape mode

Makumbi

Well-Known Member
Licensed User
Please help i have this layout in my project but i would only want only this layout to be loaded in landscape mode please find attached that small project thanks in advance
B4X:
#Region  Project Attributes
    #ApplicationLabel: BarChart
    #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 xui As XUI
    Private BarChart, LineChart As xChart
    Private Yrs As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    

    FillCharts
    'FillCharts1

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

'my vision on how to display the data
Private Sub FillCharts
    Private lstIDs, lstMarksEng, lstMarksScience, lstMarksSst, lstMarksMaths, lstNames, lstYears, lstSemesters, lstSubjects As List
    Private ResultSet1 As ResultSet
    Private Query As String
    Private StudentName As String
    lstIDs.Initialize
    lstMarksEng.Initialize
    lstMarksScience.Initialize
    lstMarksSst.Initialize
    lstMarksMaths.Initialize
    lstNames.Initialize
    lstYears.Initialize
    lstSemesters.Initialize
    lstSubjects.Initialize
    
    lstSubjects.Add("Eng")
    lstSubjects.Add("Science")
    lstSubjects.Add("Sst")
    lstSubjects.Add("Maths")
    'Name = "MAKUMBI TARIQ AZIZI"
    'Query = "SELECT Names, Total, Subject FROM Academics WHERE Names = ?"
'    Query = "SELECT ID, Names, Eng, Science, Sst, Maths, Years from students"¨
    StudentName = "Sulaiman"
    Query = "SELECT ID, Years, Semester, Eng, Science, sst, Maths FROM students WHERE Names = '" & StudentName & "'"
    
    'ResultSet1 = Starter.SQL1.ExecQuery2(Query, Array As String(Name))
    ResultSet1 = Starter.SQL1.ExecQuery(Query)
    Do While ResultSet1.NextRow
        lstIDs.Add(ResultSet1.GetLong("ID"))
'        lstNames.Add(ResultSet1.GetString("Names"))
        lstYears.Add(ResultSet1.GetInt("Years"))
        lstSemesters.Add(ResultSet1.Getstring("Semester"))
        'lstSemesters.Add(ResultSet1.GetInt("Semester"))
        lstMarksEng.Add(ResultSet1.GetInt("Eng"))
        lstMarksScience.Add(ResultSet1.GetInt("Science"))
        lstMarksSst.Add(ResultSet1.GetInt("Sst"))
        lstMarksMaths.Add(ResultSet1.GetInt("Maths"))
    Loop

    'Bar chart
    BarChart.ClearData
    
    BarChart.AddBar("Eng", xui.Color_Red)
    BarChart.AddBar("Science", xui.Color_Blue)
    BarChart.AddBar("Sst", xui.Color_Green)
    BarChart.AddBar("Maths", xui.Color_Yellow)

    For i = 0 To lstIDs.Size - 1
        'BarChart.AddBarMultiplePoint(lstYears.Get(i) & " - " & lstSemesters.Get(i), Array As Double(lstMarksEng.Get(i), lstMarksScience.Get(i), lstMarksSst.Get(i), lstMarksMaths.Get(i)))
        BarChart.AddBarMultiplePoint(lstSemesters.Get(i), Array As Double(lstMarksEng.Get(i), lstMarksScience.Get(i), lstMarksSst.Get(i), lstMarksMaths.Get(i)))
        Yrs=lstYears.Get(i)
    
    
    Next
    BarChart.YAxisName = "marks"&"-"&Yrs
    BarChart.Title = StudentName
'    BarChart.XAxisName = "total marks = " & Total
    BarChart.DrawChart
    
    'Line chart
    LineChart.ClearData
    LineChart.AddLine2("Eng", xui.Color_Red, 2dip, "CIRCLE", False, xui.Color_Red)
    LineChart.AddLine2("Science", xui.Color_Blue, 2dip, "CIRCLE", False, xui.Color_Blue)
    LineChart.AddLine2("Sst", xui.Color_Green, 2dip, "CIRCLE", False, xui.Color_Green)
    LineChart.AddLine2("Maths", xui.Color_Yellow, 2dip, "CIRCLE", False, xui.Color_Yellow)
    For i = 0 To lstIDs.Size - 1
        'LineChart.AddLineMultiplePoints(lstYears.Get(i) & " - " & lstSemesters.Get(i), Array As Double(lstMarksEng.Get(i), lstMarksScience.Get(i), lstMarksSst.Get(i), lstMarksMaths.Get(i)), True)
        LineChart.AddLineMultiplePoints(lstSemesters.Get(i), Array As Double(lstMarksEng.Get(i), lstMarksScience.Get(i), lstMarksSst.Get(i), lstMarksMaths.Get(i)), True)
        Yrs=lstYears.Get(i)
    Next
    LineChart.YAxisName =  "marks"&"-"&Yrs
    LineChart.Title = StudentName
    LineChart.DrawChart
End Sub

'your vision on how to display the data
Private Sub FillCharts1
    Private i , j As Int
    
    'Private Name As String
    Private lstIDs, lstMarksEng, lstMarksScience, lstMarksSst, lstMarksMaths, lstNames, lstYears, lstSemesters, lstSubjects As List
    Private ResultSet1 As ResultSet
    Private Query As String
    Private StudentName As String
    
    lstIDs.Initialize
    lstMarksEng.Initialize
    lstMarksScience.Initialize
    lstMarksSst.Initialize
    lstMarksMaths.Initialize
    lstNames.Initialize
    lstYears.Initialize
    lstSemesters.Initialize
    lstSubjects.Initialize
    
    lstSubjects.Add("Eng")
    lstSubjects.Add("Science")
    lstSubjects.Add("Sst")
    lstSubjects.Add("Maths")
    'Name = "MAKUMBI TARIQ AZIZI"
    'Query = "SELECT Names, Total, Subject FROM Academics WHERE Names = ?"
'    Query = "SELECT ID, Names, Eng, Science, Sst, Maths, Years from students"¨
    StudentName = "Sulaiman"
    Query = "SELECT ID, Years, Semester, Eng, Science, sst, Maths FROM students WHERE Names = '" & StudentName & "'"
    
    'ResultSet1 = Starter.SQL1.ExecQuery2(Query, Array As String(Name))
    ResultSet1 = Starter.SQL1.ExecQuery(Query)
    Do While ResultSet1.NextRow
        lstIDs.Add(ResultSet1.GetInt("ID"))
'        lstNames.Add(ResultSet1.GetString("Names"))
        lstYears.Add(ResultSet1.GetString("Years"))
        lstSemesters.Add(ResultSet1.GetString("Semester"))
        lstMarksEng.Add(ResultSet1.GetString("Eng"))
        lstMarksScience.Add(ResultSet1.GetString("Science"))
        lstMarksSst.Add(ResultSet1.GetString("Sst"))
        lstMarksMaths.Add(ResultSet1.GetString("Maths"))
    Loop

    'Bar chart
    BarChart.ClearData
    
    For i = 0 To lstYears.Size - 1
    '    BarChart.AddBar(lstYears.Get(i) & " " & lstSemesters.Get(i), xui.Color_RGB(Rnd(0, 256), Rnd(0, 256), Rnd(0, 256)))
        BarChart.AddBar( lstSemesters.Get(i), xui.Color_RGB(Rnd(0, 256), Rnd(0, 256), Rnd(0, 256)))
        Yrs=lstYears.Get(i)
    Next

    For i = 0 To lstSubjects.Size - 1
        Private Vals(lstIDs.Size) As Double
        Select lstSubjects.Get(i)
            Case "Eng"
                For j = 0 To lstIDs.Size - 1
                    Vals(j) = lstMarksEng.Get(j)
                Next           
            Case "Science"
                For j = 0 To lstIDs.Size - 1
                    Vals(j) = lstMarksScience.Get(j)
                Next
            Case "Sst"
                For j = 0 To lstIDs.Size - 1
                    Vals(j) = lstMarksSst.Get(j)
                Next
            Case "Maths"
                For j = 0 To lstIDs.Size - 1
                    Vals(j) = lstMarksMaths.Get(j)
                Next
        End Select

        BarChart.AddBarMultiplePoint(lstSubjects.Get(i), Vals)
    Next
    BarChart.YAxisName =  "marks"&"-"&Yrs
    BarChart.Title = StudentName
'    BarChart.XAxisName = "total marks = " & Total
    BarChart.DrawChart
    
    'Line chart
'    LineChart.ClearData
'    LineChart.AddLine("marks", xui.Color_Blue)
'    LineChart.AddLine2("marks", xui.Color_Blue, 2dip, "SQUARE", False, xui.Color_Blue)
'    For i = 0 To lstSubject.Size - 1
'        LineChart.AddLinePointData(lstSubject.Get(i), lstTotal.Get(i), True)
'    Next
'    LineChart.YAxisName = "marks"
'    LineChart.DrawChart
End Sub
 

Attachments

  • Screenshot_1584419910.png
    Screenshot_1584419910.png
    69 KB · Views: 203
  • Backup BarChart 2020-03-17 07.45.zip
    29.3 KB · Views: 223

josejad

Expert
Licensed User
Longtime User
Just read the code you've post

B4X:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified   '<-----------------------------------------CHANGE IT TO LANDSCAPE¡
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
B4X:
 Dim LayoutVal As LayoutValues = GetDeviceLayoutValues
 If LayoutVal.Width > LayoutVal.Height Then
  'Landscape
   Activity.LoadLayout("Main")
 Else
  'Portrait
 End If
 
Upvote 0

Makumbi

Well-Known Member
Licensed User
B4X:
Dim LayoutVal As LayoutValues = GetDeviceLayoutValues
If LayoutVal.Width > LayoutVal.Height Then
  'Landscape
   Activity.LoadLayout("Main")
Else
  'Portrait
End If
if i change this to landscape wont it affect my other layouts yet i wanted only one layout to be affected thanks
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Unfortunately, your question is not precise enough!
Do you want several layouts in your project and only the charts in landscape?
Anyway, in my opinion, having a part of the program in portrait and another one in landscape will become boring for the user.
In your layout file, you stretched only the bar chart, what do you want to do with the line chart?
Do you want to display both at the same time or alternately?
I suppose that before displaying anything you need to select in some way the data to display, this means another activity or layout.

Attached your project modified a bit, showing the charts in portrait and landscape. You can select which chart you want to display only one at each time.
Just for illustration on what can be done.

1584455249858.png
1584455312366.png
 

Attachments

  • BarChart 2020-03-17-1.zip
    29.6 KB · Views: 303
Upvote 0

Makumbi

Well-Known Member
Licensed User
I d
Unfortunately, your question is not precise enough!
Do you want several layouts in your project and only the charts in landscape?
Anyway, in my opinion, having a part of the program in portrait and another one in landscape will become boring for the user.
In your layout file, you stretched only the bar chart, what do you want to do with the line chart?
Do you want to display both at the same time or alternately?
I suppose that before displaying anything you need to select in some way the data to display, this means another activity or layout.

Attached your project modified a bit, showing the charts in portrait and landscape. You can select which chart you want to display only one at each time.
Just for illustration on what can be done.

View attachment 90177 View attachment 90178
I did not know that this kind of orientation is possible with this feature thanks very much
 
Upvote 0
Top