Android Question ScrollView On Tablet

alon

Active Member
Licensed User
Longtime User
Hi,
I am using a ScrollView and I am putting on it a few objects (dynamically) .
The problem starts when the activity is pause or when the keyboard pop up , all the views are corrupted (attach pic),
At the beginning I rebuild it on the activity resume,
But now when the keyboard popup I can't rebuild it again.
I also have notice that It happens only on tablets and on my cell everything is ok.
Is there a way to refresh the view or something like that?
p.s
I install it on 2 tablets (Samsung/asus) and in both of them I am having the same problem.
Thanks in advance
 

Attachments

  • Good.jpg
    Good.jpg
    384 KB · Views: 164
  • BadView2.jpg
    BadView2.jpg
    183.7 KB · Views: 128

alon

Active Member
Licensed User
Longtime User
This is a mistake. The UI should only be created in Activity_Create.

I recommend you to use CustomListView. It is based on ScrollView.
Each item should be implemented as a layout file and the views should be anchored properly.

Thanks Erel,
but if i need to create objects dynamically is it Possible with CustomListView?
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
but if i need to create objects dynamically

This is what a ScrollView is made for. What I do: Create the ScrollView in Activity_Create (and keep it!). Remove all views on it when needed (ScrollView.Panel.RemoveAllViews) and add them again like you want or just update them I use a Refresh Sub to do so. CustomListView does the same (as it is based on ScrollView).

Another hint: Keep all the data you want to add to the ScrollView in a List (data vs. UI) so you can access them very easy. If you need to refresh just call a sub and the ScrollView is updated based on the list. The labels you add to the ScrollView are just "containers"

Example (I'm working with %x and %y because I need the views at an exact position.

B4X:
Sub UpdateSVList
    DevicesListSV.Panel.RemoveAllViews 'remove all existing (previous) views on the SV's panel
    Dim m As Map
    For i=0 To DevicesList.Size-1 'List contains maps
        m=DevicesList.Get(i)
        Dim MacLBL As Label 'you can add any view you like

        MacLBL.Initialize("Device")
        DevicesListSV.Panel.AddView(MacLBL,1%x,i*11%y,98%x,10%y)
        'do more code to adjust textsizes, etc.
    Next
  
    DevicesListSV.Panel.Height=MacLBL.Top+MacLBL.Height+5%y 'Set new height
  
End Sub
 
Upvote 0

alon

Active Member
Licensed User
Longtime User
This is what a ScrollView is made for. What I do: Create the ScrollView in Activity_Create (and keep it!). Remove all views on it when needed (ScrollView.Panel.RemoveAllViews) and add them again like you want or just update them I use a Refresh Sub to do so. CustomListView does the same (as it is based on ScrollView).

Another hint: Keep all the data you want to add to the ScrollView in a List (data vs. UI) so you can access them very easy. If you need to refresh just call a sub and the ScrollView is updated based on the list. The labels you add to the ScrollView are just "containers"

Example (I'm working with %x and %y because I need the views at an exact position.

B4X:
Sub UpdateSVList
    DevicesListSV.Panel.RemoveAllViews 'remove all existing (previous) views on the SV's panel
    Dim m As Map
    For i=0 To DevicesList.Size-1 'List contains maps
        m=DevicesList.Get(i)
        Dim MacLBL As Label 'you can add any view you like

        MacLBL.Initialize("Device")
        DevicesListSV.Panel.AddView(MacLBL,1%x,i*11%y,98%x,10%y)
        'do more code to adjust textsizes, etc.
    Next
 
    DevicesListSV.Panel.Height=MacLBL.Top+MacLBL.Height+5%y 'Set new height
 
End Sub
thanks
 
Upvote 0

alon

Active Member
Licensed User
Longtime User
This is a mistake. The UI should only be created in Activity_Create.

I recommend you to use CustomListView. It is based on ScrollView.
Each item should be implemented as a layout file and the views should be anchored properly.

Hi Erel,

I am having the same problem with CustomListView,
But now I know what causing the problem,
When I am setting the Background of an object such as label or a button, then the view is corrupted.
Can you please tell me if there a solution for that problem,
Here is the code:
B4X:
Dim cBorderlbl AsColorDrawable
cBorderlbl.Initialize2(Colors.RGB(182,222,244) ,0  ,  2dip,  Colors.Gray)
lbl.Background = cBorderlbl

Thanks
 
Upvote 0
Top