Android Question Is this a BUG?! Why does this weird stuff happen?

persianpowerman1

Active Member
Licensed User
Longtime User
guys...

I am comparing the selected item in a Listview... to a selected item in a Spinner

and you can see the log sheet for the corresponding values... ie..

ListView1.GetItem(list1_click) = 2
and
Spinner1.GetItem(spinner_click) = 2

so when i am comparing them..
this is suppose to be a TRUE... but in the IF Then condition.. it jumps to ELSE??? why is that???
(list1_click and spinner_click)... are only to save the array No. of the item selected
is there something wrong with the code??? or does it not work with numbers????

YO!han
Problem copy.jpg
 

DouglasNYoung

Active Member
Licensed User
Longtime User
Persianpowerman,
I had similar issues only it was comparing values from a Button.Tag. If I logged both values they appeared the same, but in a compare weren't!
I suspect it was a issue of variable types, so I solved it by explicitly forcing them to be integers I.e.

B4X:
dim lval, sval as int
lval = ListView1.GetItem(list1_click)
sval = Spinner1.GetItem(spinner_click)
Log(lval=sval)

It worked for me,
Douglas
 
Upvote 0

persianpowerman1

Active Member
Licensed User
Longtime User
hey douglas.. thats what i did too.. then it worked
i saved both of them in variables.. and then compared them... it did work!
But still ... its weird.. beats my logic!?!

Erel... buddy.. heres the stuff.. i was doing a lill RnD with them... the click event of Button1 is where i got stuck...
its where im comparing a selected item from the LISTVIEW with a selected item from SPINNER

the click event of Button2.. works fine...
 

Attachments

  • IndexOf.zip
    499.1 KB · Views: 181
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You are comparing 2 with "2". The compiler cannot know the type because the variables type in this case is Object.
You should explicitly set the type.
For example:
B4X:
Dim s1 = ListView1.GetItem(list1_click), s2 = Spinner1.GetItem(spinner_click) As String
If s1 = s2 ...

Note that you should use File - Export as zip when uploading projects.
 
Upvote 0

persianpowerman1

Active Member
Licensed User
Longtime User
oh!!!! ok... i get it... thanx.. this made sense..

yup will use the file export function. .. dint know about it

guys.. thanx once again : -)
 
Upvote 0
Top