ListView scroll to pick last item problem

varayut

Member
Licensed User
Longtime User
I cant select the 2 last item even I can scroll to see its bottom line. Any help please.
code:----------------------------------------------------
Sub Activity_Create(FirstTime As Boolean)
width = 100%x
height = 100%x
canvas1.Initialize(Activity)
rect1.Initialize(0, height, width, height+300%x)
canvas1.DrawRect(rect1, Colors.Black, True, 5dip)

ListView1.Initialize("ListView1")
ListView1.AddSingleLine("1")
ListView1.AddSingleLine("2")
ListView1.AddSingleLine("3")
ListView1.AddSingleLine("4")
ListView1.AddSingleLine("5")
ListView1.AddSingleLine("6")
ListView1.AddSingleLine("7")
ListView1.AddSingleLine("8")
ListView1.AddSingleLine("9")
Activity.AddView(ListView1, 0, height, 100dip,height+150%x )
ListView1.SingleLineLayout.Label.TextSize = 12
Draw
End Sub 'Activity
Sub Draw
Activity.Invalidate
canvas1.DrawColor(Colors.White)
canvas1.DrawRect(rect1, Colors.Black, True, 5dip)

canvas1.DrawLine(0,0,width,height,Colors.Red,2dip)
canvas1.DrawLine(width/2-width/8,0,width/2-width/8,height,Colors.Red,2dip)
canvas1.DrawLine(width/2+width/8,0,width/2+width/8,height,Colors.Red,2dip)
canvas1.DrawLine(0,width/2-width/8,width,width/2-width/8,Colors.Red,2dip)
canvas1.DrawLine(0,width/2+width/8,width,width/2+width/8,Colors.Red,2dip)

End Sub 'Draw
'------------------------------------------------------
 

klaus

Expert
Licensed User
Longtime User
Your ListView height is too heigh !
As an example:
Device width 480
Device height 800

In your case:
width = 100%x = 480
height = 100%x = 480
Activity.AddView(ListView1, 0, height, 100dip, height+150%x )

Then:
ListView1.Top = height = 480
ListView1.Height = 480 + 1.5 * 480 = 1200
Bottom = Top + Height = 1680
ScreeHeight 800 - Title
So your ListView is much too heigh !

Are you sure that you want these dimensions ?

With this line the ListView will fill the bottom of the screen below the rectangle.
Activity.AddView(ListView1, 0, height, 100dip, 100%y - height)

Best regards.
 
Upvote 0

varayut

Member
Licensed User
Longtime User
ok , I agree with you Klaus about the height of listview is too much and I will change it.
But back to the problem about last item selection even I set itemHeight = 35 and then add more item to listview to 50 or more like
ListView1.AddSingleLine("9 ---> 50")
ListView1.SingleLineLayout.ItemHeight = 35
I can scroll but can not select the last 10 items.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
What's are coordinates of the ListView ?
Especially the bottom coordinate, is it out of the screen ?
If the bottom is below the bottom of the screen you wont see the last items.
You should post your code so we could see where the problem is.
Have you tried the suggestion I gave you in my post ?
I tested it on my device before posting it, and I could select all 9 items !

Best regards.
 
Upvote 0

varayut

Member
Licensed User
Longtime User
Thx for your help. The test code is here....
'Activity module test ListView
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

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 ListView1 As ListView
Dim listview2 As ListView
Dim listview3 As ListView
Dim canvas1 As Canvas
Dim rect1 As Rect
Dim width,height As Int
Dim a As String
Dim b As String
Dim c As String

End Sub

Sub Activity_Create(FirstTime As Boolean)
width = 100%x
height = 100%x

canvas1.Initialize(Activity)
rect1.Initialize(0, height, width, height+45%x)

ListView1.Initialize("ListView1")
listview2.Initialize("ListView2")
listview3.Initialize("ListView3")

ListView1.AddSingleLine("a")
ListView1.AddSingleLine("b")
ListView1.AddSingleLine("c")
ListView1.AddSingleLine("d")
ListView1.AddSingleLine("e")
ListView1.AddSingleLine("f")
ListView1.AddSingleLine("g")
ListView1.AddSingleLine("h")
ListView1.AddSingleLine("i")
ListView1.AddSingleLine("j")
ListView1.AddSingleLine("k")
ListView1.AddSingleLine("l")
ListView1.AddSingleLine("m")
ListView1.AddSingleLine("n")
ListView1.AddSingleLine("o")
ListView1.AddSingleLine("p")
ListView1.AddSingleLine("q")
ListView1.AddSingleLine("r")
ListView1.AddSingleLine("s")
ListView1.AddSingleLine("t")


listview2.AddSingleLine("1")
listview2.AddSingleLine("2")
listview2.AddSingleLine("3")
listview2.AddSingleLine("4")
listview2.AddSingleLine("5")
listview2.AddSingleLine("6")
listview2.AddSingleLine("7")
listview2.AddSingleLine("8")
listview2.AddSingleLine("9")
listview2.AddSingleLine("10")
listview2.AddSingleLine("11")
listview2.AddSingleLine("12")
listview2.AddSingleLine("13")
listview2.AddSingleLine("14")
listview2.AddSingleLine("15")
listview2.AddSingleLine("16")
listview2.AddSingleLine("17")
listview2.AddSingleLine("18")


listview3.AddSingleLine("2554")
listview3.AddSingleLine("2555")
listview3.AddSingleLine("2556")
listview3.AddSingleLine("2557")
listview3.AddSingleLine("2558")
listview3.AddSingleLine("2559")
listview3.AddSingleLine("2560")
listview3.AddSingleLine("2561")
listview3.AddSingleLine("2562")
listview3.AddSingleLine("2563")
listview3.AddSingleLine("2564")
listview3.AddSingleLine("2565")
listview3.AddSingleLine("2566")
listview3.AddSingleLine("2567")
listview3.AddSingleLine("2568")
listview3.AddSingleLine("2569")
listview3.AddSingleLine("2570")
listview3.AddSingleLine("2571")
listview3.AddSingleLine("2572")
listview3.AddSingleLine("2573")
listview3.AddSingleLine("2574")
listview3.AddSingleLine("2575")
listview3.AddSingleLine("2576")
listview3.AddSingleLine("2577")


Activity.AddView(ListView1, 0, height, 80dip,height+45%x )
Activity.AddView(listview2, 150dip, height, 40dip, height+45%x)
Activity.AddView(listview3, 200dip, height, 80dip, height+45%x)
' if less than 45%x the black rect1 area not include to the bottom
ListView1.SingleLineLayout.ItemHeight = 38
listview2.SingleLineLayout.ItemHeight = 38
listview3.SingleLineLayout.ItemHeight = 38


Draw


End Sub
Sub Draw
Activity.Invalidate
canvas1.DrawColor(Colors.White)
canvas1.DrawRect(rect1, Colors.Black, True, 5dip)

canvas1.DrawLine(0,0,width,height,Colors.Red,2dip)
canvas1.DrawLine(width/2-width/8,0,width/2-width/8,height,Colors.Red,2dip)
canvas1.DrawLine(width/2+width/8,0,width/2+width/8,height,Colors.Red,2dip)
canvas1.DrawLine(0,width/2-width/8,width,width/2-width/8,Colors.Red,2dip)
canvas1.DrawLine(0,width/2+width/8,width,width/2+width/8,Colors.Red,2dip)

canvas1.DrawText(a, width/2-width/25, height/2+height/15, Typeface.DEFAULT, 20, Colors.Red, "CENTER")
canvas1.DrawText(b, width/2, height/2+height/15, Typeface.DEFAULT, 20, Colors.Red, "CENTER")
canvas1.DrawText(c, width/2+width/3, height/2+height/15, Typeface.DEFAULT, 20, Colors.Red, "CENTER")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub ListView1_ItemClick (Position As Int, Value As Object)
'Activity.Title = Value
a = Value
Draw
End Sub
Sub ListView2_ItemClick (Position As Int, Value As Object)
'Activity.Title = Value
b = Value
Draw
End Sub
Sub ListView3_ItemClick (Position As Int, Value As Object)
'Activity.Title = Value
c = Value
Draw
End Sub
'************************************
I use AVD233 and AVD31 honeycomb of Galaxy tab 10.1 . But I cant reach the item below by scrolling.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Two first remarks:
- It would be much easier for us to help you if you posted the project as a zip file (IDE menu Files / Export As Zip) so we don't need to make a project to test you code.
- When posting code you should use code tags to show it. Click on the '#' button to generate the code tags.

Why haven't you tested the suggestion I gave you in post #2 ?

Once again test these lines:
B4X:
Activity.AddView(ListView1, 0, height, 80dip, 100%y - height)
Activity.AddView(Listview2, 150dip, height, 40dip, 100%y - height)
Activity.AddView(Listview3, 200dip, height, 80dip, 100%y - height)
To see what happens, place two Log statements just before the Activity.AddView lines.
B4X:
Log(100%y) ' thats the screen height
Log(height + height + 45%x) ' this is the bottom coordinate of the ListView
Activity.AddView(ListView1, 0, height, 80dip, height + 45%x )
The second value is heigher than the first one !
That means that the bottom of the ListView is out of the screen.

The Activity.AddView definition is the following:
Activity.AddView(View, Left, Top, Width, Height)
and not
Activity.AddView(View, Left, Top, Right, Bottom)

Best regards.
 
Upvote 0

varayut

Member
Licensed User
Longtime User
Sorry for not use #. Now I've got it Klaus , I misunderstood about the syntax of Right,Bottom. Nevertheless I really appreciate you for this helping.
 
Upvote 0
Top