T Tom_707 Member Licensed User Jul 6, 2020 #1 I have a layout which is loaded onto two different panels, which are part of a single activity: Panel1.LoadLayout("Layout1") Panel2.LoadLayout("Layout1") Layout1 has an edittext View. When I refer to the edittext View in code, for example: edtView.Text = "Text" I can only refer to the one that was loaded in the last LoadLayout, which is Panel2. How can I reference the edittext View of Panel1? Any help will be appreciated.
I have a layout which is loaded onto two different panels, which are part of a single activity: Panel1.LoadLayout("Layout1") Panel2.LoadLayout("Layout1") Layout1 has an edittext View. When I refer to the edittext View in code, for example: edtView.Text = "Text" I can only refer to the one that was loaded in the last LoadLayout, which is Panel2. How can I reference the edittext View of Panel1? Any help will be appreciated.
mcqueccu Expert Licensed User Longtime User Jul 7, 2020 #2 Why are you loading 2 layouts in one activity? I think you should use one layout and load it under activity create sub. Add the two panels on that one layout, Then add the edit text views to the panels. Upvote 0
Why are you loading 2 layouts in one activity? I think you should use one layout and load it under activity create sub. Add the two panels on that one layout, Then add the edit text views to the panels.
Erel B4X founder Staff member Licensed User Longtime User Jul 7, 2020 #3 Many ways to do it. Tip: declare the panels type to be B4XView. B4XViews are easier to work with. A simple way is to access the view based on its index: Code: Dim et As B4XView = Panel1.GetView(4) et.Text = "Text" 'or Panel1.GetView(4).Text = "Text" 'or Dim et As EditText = Panel1.GetView(4) Another way: Code: Panel1.LoadLayout("Layout1") Panel1.Tag = edtView Panel2.LoadLayout("Layout1") Panel2.Tag = edtView '.... Dim et As B4XView = Panel1.Tag et.Text = "Text" And there are many more ways to organize your references. Upvote 0
Many ways to do it. Tip: declare the panels type to be B4XView. B4XViews are easier to work with. A simple way is to access the view based on its index: Code: Dim et As B4XView = Panel1.GetView(4) et.Text = "Text" 'or Panel1.GetView(4).Text = "Text" 'or Dim et As EditText = Panel1.GetView(4) Another way: Code: Panel1.LoadLayout("Layout1") Panel1.Tag = edtView Panel2.LoadLayout("Layout1") Panel2.Tag = edtView '.... Dim et As B4XView = Panel1.Tag et.Text = "Text" And there are many more ways to organize your references.
T Tom_707 Member Licensed User Jul 7, 2020 #4 Thanks so much Erel for the help. I've figured out what the problem was. I'm just used to being able to link multiple methods in a single line to reference a property, for example: Object.Method1.Method2.Property In B4A, it seems the only way to do this is by assigning each method to a separate variable, before you can reference the final property: Variable1 = Object.Method1 Variable2 = Variable1.Method2 Variable3 = Variable2.Property For example: Code: Dim pnl As Panel Dim edt As EditText pnl = SomePanel (SomePanel has an EditText child View in position 0) edt = pnl.GetView(0) Log(edt.Text) Just something I'll have to get used to. Or is there a better way to do this? Last edited: Jul 7, 2020 Upvote 0
Thanks so much Erel for the help. I've figured out what the problem was. I'm just used to being able to link multiple methods in a single line to reference a property, for example: Object.Method1.Method2.Property In B4A, it seems the only way to do this is by assigning each method to a separate variable, before you can reference the final property: Variable1 = Object.Method1 Variable2 = Variable1.Method2 Variable3 = Variable2.Property For example: Code: Dim pnl As Panel Dim edt As EditText pnl = SomePanel (SomePanel has an EditText child View in position 0) edt = pnl.GetView(0) Log(edt.Text) Just something I'll have to get used to. Or is there a better way to do this?
Erel B4X founder Staff member Licensed User Longtime User Jul 7, 2020 #5 Please use [code]code here...[/code] tags when posting code. Upvote 0
T Tom_707 Member Licensed User Jul 7, 2020 #6 OK, no problem. I was posting 'pseudo-code' so I didn't think it was required. I'll edit it now. [Edit] I must say, I have to agree. That looks much nicer and neater! Thanks for the help Erel. Last edited: Jul 7, 2020 Upvote 0
OK, no problem. I was posting 'pseudo-code' so I didn't think it was required. I'll edit it now. [Edit] I must say, I have to agree. That looks much nicer and neater! Thanks for the help Erel.
Erel B4X founder Staff member Licensed User Longtime User Jul 7, 2020 #7 Tom_707 said: In B4A, it seems the only way to do this is by assigning each method to a separate variable, before you can reference the final property: Click to expand... No. You haven't read my answer carefully. See my code: Code: Panel1.GetView(4).Text = "Text" For this to work you need to switch to B4XView, as Panel.GetView returns a View object that doesn't have a Text property. Upvote 0
Tom_707 said: In B4A, it seems the only way to do this is by assigning each method to a separate variable, before you can reference the final property: Click to expand... No. You haven't read my answer carefully. See my code: Code: Panel1.GetView(4).Text = "Text" For this to work you need to switch to B4XView, as Panel.GetView returns a View object that doesn't have a Text property.
T Tom_707 Member Licensed User Jul 7, 2020 #8 Yes, that does the trick! A normal View has a limited amount of properties available, whereas a B4XView seems to be able to access all the properties. Thanks Erel! Upvote 0
Yes, that does the trick! A normal View has a limited amount of properties available, whereas a B4XView seems to be able to access all the properties. Thanks Erel!
T Tom_707 Member Licensed User Jul 8, 2020 #9 Erel said: No. You haven't read my answer carefully. See my code: Code: Panel1.GetView(4).Text = "Text" For this to work you need to switch to B4XView, as Panel.GetView returns a View object that doesn't have a Text property. Click to expand... Hi Erel, The B4XView does not seem to be able to access the properties of a Spinner view (or am I missing something again?). Is there another way of achieving the equivalent of: Code: B4XView.GetView(0).SelectedItem Are there any other Views that B4XView doesn't access the properties of? Last edited: Jul 8, 2020 Upvote 0
Erel said: No. You haven't read my answer carefully. See my code: Code: Panel1.GetView(4).Text = "Text" For this to work you need to switch to B4XView, as Panel.GetView returns a View object that doesn't have a Text property. Click to expand... Hi Erel, The B4XView does not seem to be able to access the properties of a Spinner view (or am I missing something again?). Is there another way of achieving the equivalent of: Code: B4XView.GetView(0).SelectedItem Are there any other Views that B4XView doesn't access the properties of?
Erel B4X founder Staff member Licensed User Longtime User Jul 8, 2020 #10 You should start a new thread for a new question. Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Jul 8, 2020 #11 You can find more information about the concepts behind B4XView here: https://www.b4x.com/android/forum/threads/b4x-xui-cross-platform-native-ui-library.84359/ Upvote 0
You can find more information about the concepts behind B4XView here: https://www.b4x.com/android/forum/threads/b4x-xui-cross-platform-native-ui-library.84359/