F fiaful Member Licensed User Longtime User Dec 9, 2012 #1 Hi there! I would need to build a function that will return me a view, contained in a panel, knowing only the name of the view (no ID, no tags) ... The panel is populated by a call to other loadlayout and later in a sub I can call asynchronously use the method call GetView, passing the index of the view that I intend to use. But since the designer I insert my view by specifying the name, I also want to take just using their name! I tried building a function in java like this: Code: Copy int Id = pBA.context.getResources().getIdentifier(Name, "id", pBA.context.getPackageName()); Log.d("B4A", "GetViewByName - Id = " + Id); View V = container.getObject().findViewById(Id); Log.d("B4A", "GetViewByName - V = " + V); return V; but the Id returned is always 0 (probably because the id is not mapped in the R class) how could I do? how do you do it? you could post a snippet that works? Thanks to all in advance for any response.
Hi there! I would need to build a function that will return me a view, contained in a panel, knowing only the name of the view (no ID, no tags) ... The panel is populated by a call to other loadlayout and later in a sub I can call asynchronously use the method call GetView, passing the index of the view that I intend to use. But since the designer I insert my view by specifying the name, I also want to take just using their name! I tried building a function in java like this: Code: Copy int Id = pBA.context.getResources().getIdentifier(Name, "id", pBA.context.getPackageName()); Log.d("B4A", "GetViewByName - Id = " + Id); View V = container.getObject().findViewById(Id); Log.d("B4A", "GetViewByName - V = " + V); return V; but the Id returned is always 0 (probably because the id is not mapped in the R class) how could I do? how do you do it? you could post a snippet that works? Thanks to all in advance for any response.
F fiaful Member Licensed User Longtime User Dec 9, 2012 #2 ah! I forgot an important detail! the layout loaded in the panel, that I mentioned above, is used as items in a listview ... then each item in the list contains all the objects loaded by the loadlayout. this excludes the possibility of creating a global map containing the view of the layout! it gets more complicated! Upvote 0
ah! I forgot an important detail! the layout loaded in the panel, that I mentioned above, is used as items in a listview ... then each item in the list contains all the objects loaded by the loadlayout. this excludes the possibility of creating a global map containing the view of the layout! it gets more complicated!
Erel B4X founder Staff member Licensed User Longtime User Dec 10, 2012 #3 Views do not really have names. You can however create such a mapping yourself: Code: Copy Sub LoadLayoutToPanel(p As Panel, file As String) p.LoadLayout(...) dim m As Map m.Initialize m.Put("Button1", Button1) m.Put("Button2", Button2) ... p.Tag = m End Sub The result is that in the Tag property of each panel you will have a map that maps between the "names" and the views. Upvote 0
Views do not really have names. You can however create such a mapping yourself: Code: Copy Sub LoadLayoutToPanel(p As Panel, file As String) p.LoadLayout(...) dim m As Map m.Initialize m.Put("Button1", Button1) m.Put("Button2", Button2) ... p.Tag = m End Sub The result is that in the Tag property of each panel you will have a map that maps between the "names" and the views.