Informatix Expert Licensed User Longtime User Jul 16, 2012 #1 Example (add a panel and fill it with many different views including labels) : Code: Sub LogLabelText(pnl as Panel) For i = 0 To pnl.NumberOfViews - 1 Log(pnl.GetView(i)) If pnl.GetView(i) Is Label Then Dim lbl As Label lbl = pnl.GetView(i) Log("TEXT=" & lbl.Text) End If Next End Sub Checkbox and EditText are considered as labels.
Example (add a panel and fill it with many different views including labels) : Code: Sub LogLabelText(pnl as Panel) For i = 0 To pnl.NumberOfViews - 1 Log(pnl.GetView(i)) If pnl.GetView(i) Is Label Then Dim lbl As Label lbl = pnl.GetView(i) Log("TEXT=" & lbl.Text) End If Next End Sub Checkbox and EditText are considered as labels.
Informatix Expert Licensed User Longtime User Jul 16, 2012 #2 Workaround: Code: Private Sub IsLabel(MyView As View) As Boolean Dim r As Reflector r.Target = MyView r.Target = r.RunMethod("getClass") Return (r.RunMethod("getName") = "android.widget.TextView") End Sub
Workaround: Code: Private Sub IsLabel(MyView As View) As Boolean Dim r As Reflector r.Target = MyView r.Target = r.RunMethod("getClass") Return (r.RunMethod("getName") = "android.widget.TextView") End Sub
Erel B4X founder Staff member Licensed User Longtime User Jul 16, 2012 #3 This is not a bug. This is how Is works. It was discussed in several threads here. You can use GetType keyword instead of the reflection solution (which is also fine).
This is not a bug. This is how Is works. It was discussed in several threads here. You can use GetType keyword instead of the reflection solution (which is also fine).
Informatix Expert Licensed User Longtime User Jul 16, 2012 #4 Erel said: This is not a bug. This is how Is works. It was discussed in several threads here. Click to expand... I missed the threads, sorry (I made a search but found nothing). I suppose you convert "is" to "instanceof". Erel said: You can use GetType keyword instead of the reflection solution (which is also fine). Click to expand... Good to know. Thank you.
Erel said: This is not a bug. This is how Is works. It was discussed in several threads here. Click to expand... I missed the threads, sorry (I made a search but found nothing). I suppose you convert "is" to "instanceof". Erel said: You can use GetType keyword instead of the reflection solution (which is also fine). Click to expand... Good to know. Thank you.
R Roger Garstang Well-Known Member Licensed User Longtime User Jul 16, 2012 #5 I had a hard time finding the threads when needing them too. Might be good to make it a sticky and/or in the documentation. The main threads I found show a test order like: Code: If Activity.GetView(i) Is Button Then Log(i & " Button") Else If Activity.GetView(i) Is EditText Then Log(i & " EditText") Else If Activity.GetView(i) Is Label Then Log(i & " Label") End If It comes down to the Class Label is in Java is like a Parent class the others derive from, so you need to test for them first since a Button and Edit view are a Label. You have the same thing in Windows development with things like a Checkbox and a Radio/Option Button both being a Button, etc.
I had a hard time finding the threads when needing them too. Might be good to make it a sticky and/or in the documentation. The main threads I found show a test order like: Code: If Activity.GetView(i) Is Button Then Log(i & " Button") Else If Activity.GetView(i) Is EditText Then Log(i & " EditText") Else If Activity.GetView(i) Is Label Then Log(i & " Label") End If It comes down to the Class Label is in Java is like a Parent class the others derive from, so you need to test for them first since a Button and Edit view are a Label. You have the same thing in Windows development with things like a Checkbox and a Radio/Option Button both being a Button, etc.