Android Question What is wrong with my conditions? My 2nd condition is not calling the correct activity or layout

yzeflores

Member
Hi, I am using ListView though it is recommended to use CutomeListView... I just wanted a simple list without extra details that is why I still used ListView but somehow in my list, which there are only 3 items to be clicked but The 1st and 3rd one works while the 2nd one doesn't what am I missing?

B4X:
Sub ListSchlLvl_ItemClick (Position As Int, Value As Object)
    If Value = "Elementary" Then
        StartActivity(Elementary)
    Else If Value = "Junior High SChool" Then '<---- here when i click Junior high school in my list the SHS activity is called instead of the JHS activity
        StartActivity(JHS)
    Else
        StartActivity(SHS)
    End If
End Sub
 

josejad

Expert
Licensed User
Longtime User
Have you tried to Log(Value) at the beggining of the sub, to see the real value you're getting?
 
Upvote 0

emexes

Expert
Licensed User
B4X:
If Value = "Elementary" Then
    StartActivity(Elementary)
...
While you're at it, maybe consider using Select .. Case .. End Select eg:

B4X:
Select Value
    Case "Elementary":
        StartActivity(Elementary)

    Case "Junior High School":
        StartActivity(JHS)
      
    Case Else:
        StartActivity(SHS)

End Select

or even:

B4X:
Select Value
    Case "Elementary":         StartActivity(Elementary)
    Case "Junior High School": StartActivity(JHS)
    Case "Senior High School": StartActivity(SHS)
    Case Else:                 StartActivity(MostlyPeacefulProtest)
End Select
 
Last edited:
Upvote 0
Top