Select an item in spinner will make a button or view "gone"

Asmoro

Active Member
Licensed User
Longtime User
Hi everyone,

I'm trying to figure it out how to make a behaviour that once you select
an item in a spinner, a button or view will be "gone" from the screen(menu).

This is very convenient to me, especially if you have a one (fill form)
screen activity, a lack of space or it's function related behaviour.

You can handle this in Eclipse, but how do you that in the b4a program.
Yes, I saw the visibility function here, but there's is no "gone" handling.

It would be nice if someone out there knows the answer or direction and
will gladly to explane that.

Thanks for now,

grtz,
Asmoro
 

Asmoro

Active Member
Licensed User
Longtime User
Hi Erel,

Thanks for the reply, but can I place another view or button on it's place/space instead.

And how about to put this handling in the code.

Something like this:

Sub spinner2_ItemClick (Position As Int, Value As Object)
spinner2_ItemClick = Car 'selected item'
spinner3.Visible=False
editText.Visible=True
End Sub
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can place another view in the button's position (that is true even if the button is not hidden).

This code is incorrect: spinner2_ItemClick = Car 'selected item'
your code should be something like:
B4X:
Sub spinner2_ItemClick (Position As Int, Value As Object)
If Value = "Hide button1" Then 'this is the item text
  Button1.Visible = False
End If
End Sub
 
Upvote 0

Asmoro

Active Member
Licensed User
Longtime User
I thought so .....get errors during compiling.
So how does it really has to look then, if I may ask?
 
Upvote 0

Asmoro

Active Member
Licensed User
Longtime User
Nice, but I tried without the "End If" and worked also.
What benefit has it using the "End If" then, I wonder.
 
Upvote 0

Asmoro

Active Member
Licensed User
Longtime User
Hi Erel,

It seems that I still have an error after all, even with your 'End If'.
I tried all kind of ways, but nothing worked.

I give you some part of the code to look at (note: I have 12 spinners and few editText):

Sub Spinner2_ItemClick (Position As Int, Value As Object)

If Value = "Hide Spinner3" Then Motor = True
If Value = "Hide edtTitel" Then Motor = True
edtTitel.Visible = False
If Value = "Show edtModel" Then Motor = True
edtModel.Visible = True
If Value = "Show edtBouwjaar" Then Motor = True
edtBouwjaar.Visible = True
End If
End Sub

//down below is the error I've got, did I miss something?//

Compiling code. Error
Error parsing program.
Error description: Missing Keyword: end sub
Occurred on line: 441
End If

grtz,
Asmoro
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
With an If... Then line if you include something afer the Then, it is assumed that only that statement is subject to the If - so no End If is required.

So your code has
4 If.....Then statements as numbered below.

B4X:
Sub Spinner2_ItemClick (Position As Int, Value As Object)

If Value = "Hide Spinner3" Then Motor = True             #1
If Value = "Hide edtTitel" Then Motor = True              #2
edtTitel.Visible = False             
If Value = "Show edtModel" Then Motor = True           #3  
edtModel.Visible = True
If Value = "Show edtBouwjaar" Then Motor = True       #4
edtBouwjaar.Visible = True
End If
End Sub

Because of this, the "End If" is seen as an error.

I am guessing that the statements after #2, #3 and #4 are meant to be part of the preceeding If..Then, if so your code should be
B4X:
Sub Spinner2_ItemClick (Position As Int, Value As Object)

If Value = "Hide Spinner3" Then Motor = True 

If Value = "Hide edtTitel" Then 
Motor = True
edtTitel.Visible = False
End If

If Value = "Show edtModel" Then 
Motor = True
edtModel.Visible = True
End If

If Value = "Show edtBouwjaar" Then 
Motor = True
edtBouwjaar.Visible = True
End If

End Sub
 
Upvote 0

Asmoro

Active Member
Licensed User
Longtime User
Thanks Kickaha for your explanation.
According to your code...1 question: why not a 'End If' after 'If Value = "Hide Spinner3" Then Motor = True'.

And is there a better way (read much cleaner) to code a spinner makes a combi with
the chosen other spinners and views to be visible.

Asmoro
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Thanks Kickaha for your explanation.
According to your code...1 question: why not a 'End If' after 'If Value = "Hide Spinner3" Then Motor = True'.

And is there a better way (read much cleaner) to code a spinner makes a combi with
the chosen other spinners and views to be visible.

Asmoro

To answer your first question:

With If....Then there are two variations

1) When you only want to excecute ONE statement when If is true
2) When you want to excecute multiple statements when If is true

In case 1

You include the statement ON THE SAME LINE after the "Then" and you do not need an End If - example with the single statement in bold
B4X:
If Value = "Hide Spinner3" Then [B]Motor = True[/B]

In case 2

You include the statements starting on the LINE AFTER the "Then", this requires an End If so the program Knows when it ends - example with statements in bold
B4X:
If Value = "Show edtModel" Then 
[B]Motor = True
edtModel.Visible = True[/B]
End If

The line you are asking about comes under 1)

The answer to 2 is - without seeing the code and knowing the aims of the program it is almost impossible to generalise. If you can give more info we can try to help.
 
Last edited:
Upvote 0

Asmoro

Active Member
Licensed User
Longtime User
Well, I understand the If...Then much better now.
It made sense that it worked once before without the 'End If' when compiling and
was'nt perfect in the end.

Here's more info in general:

I use one fill form screen, still to figure out how to that in code, with 12 spinners and
for now 3 textviews.

Depending of the chosen selected item of the main spinner, other spinners and/or views which are relevant to that one, will be visible and the rest of the views invisible.

Hope that you understand what I'm saying.

Asmoro
 
Last edited:
Upvote 0

Asmoro

Active Member
Licensed User
Longtime User
Update:

Solution was made and there are examples available for this handling.

You can find it at the forum basic4android-getting-started-tutorials, thread 'press-button-makes-spinner-(in)visible-examples'.

grtz.
Asmoro
 
Upvote 0
Top