Android Question (SOLVED)why refresh on scrollview always go to next panel(refresh activity)

harry2017

Member
Licensed User
dear forum I have a problem here
the case is first load scrollview panel its no problem but after I want to refresh activity to get new data or reload scrollview panel place alway go to the next panel and after I use remove view , panel that I removeview blank and new data is on the next panel.
alway like that ,but if the first load scrollview panel its ok
B4X:
    Private SV1 As ScrollView
    Private numItems As Int
    Private posTop As Int
    Private lblDescription As Label
    Private bmp As Bitmap
   
    Private ImageView1 As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
       
    Activity.LoadLayout("1") 'load the layout file
    bmp.Initialize(File.DirAssets,"smiley.png")
    '###      You should really be Declaring and initializing your sql object in the starter service  .. see comments in service
    '#####  You can call the SQL object now with  ......   Starter.SQL1
   
   
   
    '##### Get Data from DB and update views with the relevant data ...
   
    ' listtombol = DBUTILS.ExecuteMemoryTable(Starter.SQL1, "SELECT kdobat, nmobat, satuan,harga,nmkategori,foto FROM tb_obat", Null,0)
   
    list
   
End Sub

Sub list
   
    Dim nCount As Int
    nCount = SV1.panel.NumberOfViews
    'For i = 0 To nCount - 1
    For i = nCount - 1 To 0 Step -1

        SV1.Panel.RemoveViewAt(i)
   
    Next
   
    For i = 1 To 4
        numItems = numItems+1
       
        Dim p As Panel
        p.Initialize("")
        p.LoadLayout("RowItem")
       
        lblDescription.Text = $"description  ${numItems}"$    'ie description of db item
        ImageView1.Bitmap = bmp                                            'and the item image
       
        'Add a new Item Layout to the Scrollview
       
        If numItems Mod 2 <> 0 Then                                    'if Number of loaded items is uneven (1 , 3, 5 )  load at Left Position & current posTop setting
            SV1.Panel.AddView(p, 5dip, posTop + 5dip , 160dip, 180dip)
                               
        Else                                                                                    'if Number of loaded items is even (2 , 4, 6 ) load at Right Position & current posTop setting
            SV1.Panel.AddView(p, 180dip, posTop + 5dip, 160dip, 180dip)
            posTop = posTop + 210dip                                        '@@  then increase posTop Setting
           
        End If
                   
    Next
   
    SV1.Panel.Height = (Ceil(numItems / 2)) * 215dip 'Set the inner panel height according to the number of Loaded Items
   
End Sub

Sub lblMinus_Click
   
    'Get the parent panel of the clicked label
    Dim lbl As Label = Sender   
    Dim p As Panel = lbl.Parent
    Dim l As Label = p.GetView(6)        'get the panel view at the given index .. Refer to the Layout View Tree Tab (in Designer) for index order !
   
    If l.Text > 1 Then l.Text = NumberFormat2( l.Text - 1, 0, 0, 0,False)
   
End Sub

Sub lblAdd_Click
   
    'Get the parent panel of the clicked label
    Dim lbl As Label = Sender   
    Dim p As Panel = lbl.Parent
    Dim l As Label = p.GetView(6)        'get the panel view at the given index .. Refer to the Layout View Tree Tab (in Designer) for index order !
   
    l.Text = NumberFormat2( l.Text + 1, 0, 0, 0,False)
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    list
End Sub
 

Attachments

  • 30-11-2017 15.23.png
    30-11-2017 15.23.png
    75.8 KB · Views: 247
  • 30-11-2017 15.22.png
    30-11-2017 15.22.png
    66.6 KB · Views: 288
  • 30-11-2017 15.21.png
    30-11-2017 15.21.png
    75.7 KB · Views: 249
  • ScrollView Example12.zip
    168.4 KB · Views: 202

harry2017

Member
Licensed User
As several members already told you, it will be simpler to implement it with CustomListView.
Hi erel could you give me an example ...I want to know how to do it because an example from other member not like that
I ll attach example from other member here
sorry erel Im newbie for B4a I know only Vb

regard

harry
 

Attachments

  • 30-11-2017 15.28.png
    30-11-2017 15.28.png
    64.9 KB · Views: 196
  • CLV Example 2.zip
    26.8 KB · Views: 212
Upvote 0

harry2017

Member
Licensed User
You need to add posTop = 0 before For i = 1 To 4
Remove all codes is simpler with: SV1.Panel.RemoveAllViews
B4X:
Sub list
    SV1.Panel.RemoveAllViews

    posTop = 0
    For i = 1 To 4
        numItems = numItems+1
thanks klaus for the code ... but numItems alway grow up first 1 to 4 after refresh 5 to 8 refresh again 9 to 12 next ..next ...

regard

harry
 

Attachments

  • 30-11-2017 15.37.png
    30-11-2017 15.37.png
    73.7 KB · Views: 223
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
I thought the CLV Example did want you explained in your previous thread ??

Are you saying it is just Refreshing Data that is the problem ? (The example did Not include that)

If this is Not the Case ... Use the Example CLV in post #4 to build a BASIC example of what you are trying to do (don't worry about working with DB's for the time being .. just use a couple of subs and maps .. As In The Example) to show us what you are trying to do and what problem you are having'
Make sure you Comment it Well .
 
Upvote 0

harry2017

Member
Licensed User
I thought the CLV Example did want you explained in your previous thread ??

Are you saying it is just Refreshing Data that is the problem ? (The example did Not include that)

If this is Not the Case ... Use the Example CLV in post #4 to build a BASIC example of what you are trying to do (don't worry about working with DB's for the time being .. just use a couple of subs and maps .. As In The Example) to show us what you are trying to do and what problem you are having'
Make sure you Comment it Well .
dear mangojack ...I have deadline to make aplication here ,,,after fix wih scrolview I'll make with customlistview ..I must learning about customlistview again ..Im afraid I have much question about that ..and I must finish my aplication first after that I want to Update with customlistview

regard

harry
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
dear mangojack ...I have deadline to make aplication here ,,,after fix wih scrolview I'll make with customlistview ..I must learning about customlistview again ..Im afraid I have much question about that ..and I must finish my aplication first after that I want to Update with customlistview

OK ..

So you have solved problem with scrollview ?. Resetting numItems variable fixed it for you ?.
 
Upvote 0
Top