Android Question Refresh program at click button

mogenskilde

Member
Licensed User
Longtime User
Hello All

After 2 years of pause, I'm trying to build more Android apps.

I've attached a zip of an partly made application, I've search around in here and found no answer on how to make the program do a new calculation of "moment" (see zip to clarify).

I want my application to refresh the value of "moment" when one of the buttons is pressed, only way for me to make a new calculation, is to repick in the spinner ...

Thank you in advance
 

Attachments

  • recalculating at click button.zip
    7.6 KB · Views: 112

sorex

Expert
Licensed User
Longtime User
you should move the calculation out of the click event and put it in a sub that can be used from several places.

B4X:
Sub Spinner1_ItemClick (Position As Int, Value As Object)
    calc      
End Sub

Sub calc
Select Spinner1.SelectedItem
Case "M5"
moment = (4.6*lubfaktor*gradefaktor)
EditText1.Text=NumberFormat(moment,0,1)

Case "M6"
moment = (7.8*lubfaktor*gradefaktor)
EditText1.Text=NumberFormat(moment,0,1)
End Select
End Sub
 
Upvote 0

mogenskilde

Member
Licensed User
Longtime User
Hello Sorex
Thank you for the fast reply, however i still do not get a new value when clicking one of the buttons

I want to run like:
click "metrisk"
click "tør samling"
click "HEX 8.8"
Select "M5" (in spinner)
I now get a wanted value in the EditText box

next I want to :
click HEX10.9 and get a new value in EditText box

To refresh this value I have to reselect in the spinner, but I want it to show a new value when the "HEX10.9" is clicked

Hope you can see my point

TIA
Mogens
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
you need to place the "calc" call in every button's click event if you want to recalc when it's pressed

you might need to add additional check tho, to prevent recalculation when not all required "items" have been selected.
 
Upvote 0
Top