Uncheck radio button?

Malky

Active Member
Licensed User
Longtime User
Hi, at the moment I only have two Radiobuttons on a single panel.

After selecting one, I save the index value to my database.

If I restart and select an option to return to defaults, this means I have to check the first one and uncheck the second one. The result is they both end up checked which I thought shouldn't happen?

B4X:
Sub CreateSettingsPanel
   Price = SQL1.ExecQuerySingleResult("SELECT value FROM system where var = 'price'")
   prop_type = SQL1.ExecQuerySingleResult("SELECT value FROM system where var = 'prop_type'")
   Dim HeightTop
   Activity.AddView(pnlSettings, 0, 0, 100%x, 100%y)
   Dim sqlRowCount As Int
   Dim Cursor1 As Cursor
   Cursor1 = SQL1.ExecQuery("SELECT id, " & language & ", prop_type FROM settings order by prop_type")
   Log("count = " & Cursor1.RowCount)
   sqlRowCount= Cursor1.RowCount
   Dim btndefaultsettings, btnSaveSettings,btnCancelSettings As Button
   Dim radButtons(sqlRowCount) As RadioButton
   btndefaultsettings.Initialize("btnDefaultSettings")
   btnSaveSettings.Initialize("btnSaveSettings")
   btnCancelSettings.Initialize("btnCancelSettings")
   edtPrice.Initialize("edtPrice")
   edtPrice.Hint = DictionList(5)
   edtPrice.InputType =edtPrice.INPUT_TYPE_NUMBERS
   edtPrice.ForceDoneButton = True
   edtPrice.HintColor = Colors.gray
   HeightTop = 50dip
   pnlSettings.AddView(btndefaultsettings, 0dip, 0dip, 100%x, HeightTop) 'Height 50
   Log("Settings count = " & sqlRowCount)
   For i = 0 To sqlRowCount - 1
   Cursor1.Position = i
   
      Dim Rad As RadioButton
      
      Rad.Initialize("RadButton")
      Rad.Text = Cursor1.getstring(language)
      Rad.Tag = Cursor1.GetString("prop_type")
      If i = prop_type Then
         Log("Rad true = " & i)
         Rad.Checked = True
         'DoEvents
      Else
         Log("Rad false = " & i)
         Rad.Checked = False
      End If
      
      radButtons(i) = Rad
      pnlSettings.AddView(Rad,5dip, HeightTop + 5, pnlSettings.Width, 50dip)
      HeightTop = HeightTop + 55dip
      
   Next
   If Price = 1000000 OR Price =0 Then
      edtPrice.Text = ""
   Else
      edtPrice.Text = Price
   End If
   pnlSettings.AddView(edtPrice, 0dip, HeightTop + 5dip, 48%x, 50dip) 'Height 50
   HeightTop = HeightTop + 55dip
   pnlSettings.AddView(btnSaveSettings, 0dip, HeightTop + 5dip, 48%x, 50dip) 'Height 50
   pnlSettings.AddView(btnCancelSettings, 49%x, HeightTop + 5dip, 48%x, 50dip) 'Height 50
   btnCancelSettings.Text = DictionList(20)
   btnSaveSettings.Text = DictionList(19)
   btndefaultsettings.Text = DictionList(4)
   'pnlSettings.Visible = True
End Sub

Any ideas?

Malky
 

klaus

Expert
Licensed User
Longtime User
Here you are.
There is still a strange behaviour here.
When I rerun the program on my device I get the menu panel but nothing happens !
Clicking on any item, nothing.
You call quite often the FillMenuScrollView routine.
In this routine you add each time new panels but you never remove the previous ones ?

Best regards.
 

Attachments

  • homer4.zip
    86.2 KB · Views: 243
Upvote 0

Malky

Active Member
Licensed User
Longtime User
Hi Klaus, I'm sure I was told in a previous post that the panels get overriden and there's no benefit to removing and recreating them for that example and as they work ok, I have been happy to leave it like that?

If you would recommend removing panels etc first and recreating them, then I will bow to your superior knowledge and do this.

The only time I had that problem with the menu was when I had an error in the previous run or the app wasn't closed correctly. When this happened, I always had to completely un-install and re-install the app.

Anyway, just finished gardening thankfully and will follow your earlier advice for the radiobutton panel.

Once again, many thanks for your time and patience.

Malky
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The problem when you don't remove previous views you are always adding new ones on top of the previous ones.
If you add 10 views in a routine and run it 10 times you finaly have 100 views and 90 for nothing.
I'm afraid that you have this problem in FillMenuScrollView.
Perhaps the problem when nothing happens when running the program a second time is due to this. I haven't analysed it.
In the code I posted I remove the previous RadioButtons before adding new ones.

Best regards.
 
Upvote 0

Malky

Active Member
Licensed User
Longtime User
Hi Klaus, thanks once again, I will amend the code accordingly.

This is probably due to my naivety and ignorance. I assumed if every panel and sub component was the same as the first, then the original would be overwritten when recreated with the same name?

Thanks you for making me aware of this. Coincidentally, a few times I have considered that there could be a memory problem or leak when doing a lot of testing and as you say, if I am creating many instances of the same view then that would explain it.

You didn't also write the 10 commandments did you

Malky
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…