Android Question How To Reset Views in a ScrollView

Mahares

Expert
Licensed User
Longtime User
After saving a record in a SQLite table whose data values are extracted from several spinners, edittext and checkbox views, I would like to reset all views to all blanks in preparation for entering data for a new record. The below code does not seem to reset the views. Can anyone correct it or offer a better way?

B4X:
For i=0 To  scvInternal.Panel.NumberOfViews-1
    If scvInternal.Panel.GetView(i) Is EditText  Then
      Dim edtView As EditText
      edtView=scvInternal.Panel.GetView(i)
      edtView.Text=""
     Else If scvInternal.Panel.GetView(i) Is Spinner  Then
      Dim spnView As Spinner
      spnView=scvInternal.Panel.GetView(i)
      spnView.SelectedIndex=0
    Else If scvInternal.Panel.GetView(i) Is CheckBox  Then
      Dim chkView As CheckBox
      chkView=scvInternal.Panel.GetView(i)
      chkView.Checked=False
    End If
  Next
Thank you
 

Mahares

Expert
Licensed User
Longtime User
The scrollview is created in the designer, but the views are created by code. Here is an excerpt:
B4X:
scvInternal.Panel.Height=MyLabel.Length*75
B4X:
For i=0 To MyLabel.Length-1
		Dim lbl As Label
		lbl.Initialize("")
		scvInternal.Panel.AddView(lbl,0,i*70dip+20dip,65%x,60dip)
		lbl.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
		lbl.Text=MyLabel(i)  
		lbl.Typeface=Typeface.DEFAULT_BOLD
		lbl.TextSize=18
		'BELOW PREPARE CHECKBOXES SPINNERS, EDITTEXT, Labels PLACEMENT ON SCROLLVIEW
		If i=0 Then
			scvInternal.Panel.AddView(chkTbg,70%x,i*70dip+20dip,10%x,60dip)
			scvInternal.Panel.AddView(chkTbgN,85%x,i*70dip+20dip,10%x,60dip)	
		End If
		If i=1 Then
	    scvInternal.Panel.AddView(chkTbgProd,70%x,i*70dip+20dip,10%x,60dip)
			scvInternal.Panel.AddView(chkTbgProdN,85%x,i*70dip+20dip,10%x,60dip)	
		End If
		If i=2 Then 'number of tanks
			scvInternal.Panel.AddView(spnNumbTanks,70%x,i*70dip+20dip,30%x,50dip)			
		End If              
               'Here rest of code for other views


I did not set a breakpoint, but when I am inputting data for the second record, all views show the input from the previous record I just entered and none is reset unless I actually put something like: chkTbgProdN.enabled=false
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Merci Klaus:
I will see if I can condense the code and create a small project to reproduce the issue, but in the meantime, I added the below code. It seems to reset and clear all edittext, all checkboxes, but not the SPINNERS. The spinners still show the selected items from the previous record saved.
B4X:
scvInternal.Panel.RemoveAllViews  ' immediately after the 1st record is saved	
InspectScrollView  'This is the sub that creates all  the views in code
 
Upvote 0
Top