Android Question Listview won't scroll to last item

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

I have a listview that won't scroll to the last item.
This happens on both "The" Emulator [The one used in the Beginners Guide] and a real Note 3.
I have found a couple of references/questions relating to this problem but no solution.

Any help appreciated.

Regards Roger
 

sorex

Expert
Licensed User
Longtime User
I bet you used .height=100%y while it is not completely at the top.

100%y is the screenheight and not the height of the container/panel its in.
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
LucaMs
Code below, not sure it will help. I don't think it's a resize issue. The code was developed on [and sized to] the emulator that is showing the problem. No resizing.

sorex,
Sorry, no .height=100%y used.


I have a solution in mind but feel it's a crude work-around and not really solving the problem.

Regards Roger


B4X:
#Region  Project Attributes
    #FullScreen: True
    #IncludeTitle: False
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName: 1.00
    #SupportedOrientations: Portrait
    #VersionName:  1.0
#End Region

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

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
        Dim   Constants(20,3) As String

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim ConstantsView As ListView
    Dim lblTitle, ConstantsLabel As Label   

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("Portrait")
    ConstantsView.Initialize("ConstantsView")
   
    If FirstTime Then   
        add_menu
    End If
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub add_menu
'Fill Constants Array.
    Dim InputString
'Name
    For Name = 0 To 19
        Select Name
        Case 0
            InputString = "Acceleration by Gravity"
        Case 1
            InputString = "Atomic Mass Unit"       
        Case 2
            InputString = "Avogadro's Number"   
        Case 3
            InputString = "Bohr radius"       
        Case 4
            InputString = "Boltzmann constant"   
        Case 5
            InputString = "Electron charge/mass ratio"
        Case 6
            InputString = "Electron classical radius"       
        Case 7
            InputString = "Electron mass energy"       
        Case 8
            InputString = "Electron rest mass"       
        Case 9
            InputString = "Faraday constant"       
        Case 10
            InputString = "Fine-Structure constant"   
        Case 11
            InputString = "Gas constant"
        Case 12
            InputString = "Gravitational constant"   
        Case 13
            InputString = "Neutron mass energy"       
        Case 14
            InputString = "Neutron rest mass"   
        Case 15
            InputString = "Planck constant"   
        Case 16
            InputString = "Proton mass energy"       
        Case 17
            InputString = "Proton rest mass"       
        Case 18
            InputString = "Rydberg constant"   
        Case 19   
            InputString = "Speed of light"
        End Select
        Constants(Name,0) = InputString
    Next
   
'Value
    For Value = 0 To 19
        Select Value
        Case 0
            InputString = "9.8"
        Case 1
            InputString = "1.66E-27"       
        Case 2
            InputString = "6.022E23"       
        Case 3
            InputString = "0.529E-10"       
        Case 4
            InputString = "1.38E-23"       
        Case 5
            InputString = "-1.7588E11"       
        Case 6
            InputString = "2.818E-15"       
        Case 7
            InputString = "8.187E-14"       
        Case 8
            InputString = "9.109E-31"       
        Case 9
            InputString = "9.649E4"       
        Case 10
            InputString = "7.297E-3"       
        Case 11
            InputString = "8.314"
        Case 12
            InputString = "6.67E-11"       
        Case 13
            InputString = "1.505E-10"       
        Case 14
            InputString = "1.675-27"   
        Case 15
            InputString = "6.626E-34"       
        Case 16
            InputString = "1.503E-10"       
        Case 17
            InputString = "1.6726E-27"       
        Case 18
            InputString = "1.0974E7"   
        Case 19   
            InputString = "2.9979E8"
        End Select
        Constants(Value,1) = InputString
    Next
   
'Units
    For Units = 0 To 19
        Select Units
        Case 0
            InputString = "m s^-2"
        Case 1
            InputString = "kg"       
        Case 2
            InputString = "mol^-1"       
        Case 3
            InputString = "m"       
        Case 4
            InputString = "J K^-1"   
        Case 5
            InputString = "C kg^-1"       
        Case 6
            InputString = "m"       
        Case 7
            InputString = "J"       
        Case 8
            InputString = "kg"       
        Case 9
            InputString = " C mol^-1"       
        Case 10
            InputString = ""       
        Case 11
            InputString = "J mol^-1 K^-1"
        Case 12
            InputString = "Nm^2kg^-2"       
        Case 13
            InputString = "J"       
        Case 14
            InputString = "kg"       
        Case 15
            InputString = "J s"       
        Case 16
            InputString = "J"       
        Case 17
            InputString = "kg"       
        Case 18
            InputString = "m^-1"   
        Case 19   
            InputString = "m/s"
        End Select
        Constants(Units,2) = InputString
    Next

End Sub

Sub ConstantsRecall
    Dim temp As String
                            'Set the parameters for displaying the Items of the ListView
    ConstantsLabel = ConstantsView.SingleLineLayout.Label    '
    ConstantsLabel.TextColor = Colors.White                '
    ConstantsLabel.TextSize = 14
    ConstantsLabel.Color = Colors.DarkGray                '
    ConstantsLabel.Height = 7%y                         'Label height and Item Height should match to avoid gsps & overlaps
    ConstantsView.SingleLineLayout.ItemHeight = ConstantsView.SingleLineLayout.Label.Height
    ConstantsView.Color = Colors.DarkGray               
    ConstantsView.Clear                                            'Clear Listview before populating or else you get duplicates
    For Const = 0 To 19                                            'Builds the viewable list ConstantsView
        temp = Constants(Const,0)                            'Get the value from the List
        temp = temp & " " & Constants(Const,1)
        temp = temp & Constants(Const,2)
        ConstantsView.AddSingleLine(temp)            'Store the string in the ListView
    Next
    Activity.AddView(ConstantsView, 0, 10%y, 100%x, 100%y)   'Displays the list built by the previous loop.
    lblTitle.Text = "Constants"                                                        'Label sits above ConstantsView
    lblTitle.BringToFront
    lblTitle.Height = 10%y
    lblTitle.width = 100%x
    lblTitle.Top = 0%y

End Sub

Sub ConstantsView_ItemClick (Position As Int, ResultsValue As Object)
    Dim temp As String
    Log Constants(Position,1)                                'Capture the value .
    ConstantsView.RemoveView                        'Exit ListView.
    lblTitle.SendToBack
End Sub
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
B4X:
Activity.AddView(ConstantsView, 0, 10%y, 100%x, 100%y)

should be

B4X:
Activity.AddView(ConstantsView, 0, 0, 100%x, 100%y)

?

it goes 10% ofscreen with the original code

or use

B4X:
Activity.AddView(ConstantsView, 0, 10%y, 100%x, 90%y)

if you want to keep that 10% padding
 
Upvote 0
Top