Is it correct to assume that the index of a new View that's just been added, is the total number of Views + 1? As illustrated in the following example:
B4X:
NoOfViews = Activity.GetAllViewsRecursive.Size 'is this syntax correct?
Activity.AddView(lblView, 0, 0, 100dip, 30dip) 'add a new View
lblView.Tag = NoOfViews 'will this be the correct index of the new View?
.
.
.
.
Activity.GetView(lblView.Tag).Top = 100dip 'use the stored index to access the correct view
Just to clarify.
I suggested NoOfViews = Activity.NumberOfViews
because in the code example in post#1 the call was made before lblView was added to the Activity.
After adding, the index of lblView will, of course, be Activity.NumberOfViews - 1
Another question I have that's related to this is:
If Views don't have indexes, then what is the point of the Activity.GetView(index) method? What index are you supposed to use there?
What do you mean by that? every view added to the activity has an index : example if the activity has 2 labels the first label index is 1 and second label index is 2
example if the activity has 2 labels the first label index is 0 and second label index is 1
then what is the point of the Activity.GetView(index) method? What index are you supposed to use there?
What do you mean by that? every view added to the activity has an index :
example if the activity has 2 labels the first label index is 1 and second label index is 2
What do you mean by that? every view added to the activity has an index :
example if the activity has 2 labels the first label index is 1 and second label index is 2
If I use Activity.RemoveViewAt to delete the first label, what will be the index of the second label (ignoring 0-based indexing)? Will it go to 1, or stay at 2?
If I use Activity.RemoveViewAt to delete the first label, what will be the index of the second label (ignoring 0-based indexing)? Will it go to 1, or stay at 2?
My app has a dynamic layout, where Views are added or deleted constantly during run-time, based on various criteria.
I want to be able to access a View directly via its Tag or ID, and then work with it. I don't want to have to keep track of every time the layout changes. And finding a View by cycling through ALL Views, every single time I want to work on a View, seems so haphazard. As in the following code:
B4X:
For Each v As View In Activity.GetAllViewsRecursive
If v.Tag = 5 Then 'Using 5 as an example
v.Width = 100dip
End If
Next
Android has the following method:
Java:
public final T findViewWithTag (Object tag)
So basically my question is this - is there any way to achieve something like this in B4X:
B4X:
Private v As View
.
.
v = Activity.FindViewWithTag(5)
v.Width = 100dip
Sorry, but I still don't understand why and what for?
How do you know that the view you want access has tag 5?
You need to memorize the Tag somewhere, so why not remember lblView ?