Custom Control/ Vew Equivalents?

kanaida

Active Member
Licensed User
Longtime User
Is there something in B4A like a user control in vb? i guess a custom view in the android world.

I would like to display it like business cards on top of each other like music players show albums sometimes:

Type: Owner
Name: Bobby Brown
Phone: 555-555-5555 [Call Button]
-----------------------
Type: Company
Name: Magic Corp
Phone: 555-555-5555 [Call Button]
-----------------------
Type: Buyer
Name: Bobby Brown
Phone: 555-555-5555 [Call Button]

Right now I have been using 2 functions to do this:
AddTextField(p as Panel,LabelText as string, Text as string, DataField as string)
AddPhoneField(p as Panel,LabelText as string, Text as string, DataField as string)

(Datafield is the SQLite field, so I can use the same event handler for all items, and read the .Tag property to save back data as they type)

Is there some kind of way I can do this but with the designer instead of calculating a ton of x/y values for placement?

Right now I'm using a modified version of this as Erel pointed me to before:
http://www.b4x.com/forum/basic4android-getting-started-tutorials/7221-list-two-columns-checkbox.html#post41354
 
Last edited:

kanaida

Active Member
Licensed User
Longtime User
That's what I kind of figured.

Hopefully in the future we can make something like a panel in the designer, with other views in it that we can re-use somehow by adding that pre-filled panel to other views in our activity. Generating a new class in a library from that design file called CustomControls would be awesome. Then if possible somehow we'd just overwrite the event handler for the properties of that class.

I guess the end result would be with what you did with the ListView, the properties called 2LinesAndBitmap. except as an object by itself so we can just add it to a panel.

I'm not too proficient at doing things like this yet:
[label 60dip] [TextEdit 100% not used by other controls - Panel Borders] [Button1 40dip] [Button2 40dip]

I don't know how to write java, but if it's anything like B4A as far as methods go etc... then perhaps it'll be easier to learn how to make a library with custom control classes/types. Then using those in B4A.

I'll look at the other posts to see how to make one. Hopefully it's as easy as it sounds and I can share a library with other people on the forum, adding new custom views as I go along.
 
Upvote 0

steinundfoete

New Member
Licensed User
Longtime User
>You will need to do it programmatically.
Does it mean, I can program a library with a custom control in Eclipse and use it then inside B4a? How???
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
That's what I kind of figured.

Hopefully in the future we can make something like a panel in the designer, with other views in it that we can re-use somehow by adding that pre-filled panel to other views in our activity.

This is already possible: Create a layout with the views you want, save it...Load it in to a Panel!! then you can access the panels views by their index.
 
Upvote 0

steinundfoete

New Member
Licensed User
Longtime User
Exception on CanvasWrapper.Initialize

Wow that's great news :)


Here my code snippet:

public void Initialize(final BA ba, ViewGroup Panel, String EventName) throws Exception
{
m_EventName = EventName;
m_BA = ba;
m_Panel = new PanelWrapper();
m_Canvas = new CanvasWrapper();
m_Panel.Initialize(m_BA, m_EventName);
m_Canvas.Initialize(m_Panel.getObject());
}

the canvas seems to be ok: anywheresoftware.b4a.objects.drawable.CanvasWrapper@4056c0a8
m_Panel.getObject() seems to return a valid object: anywheresoftware.b4a.BALayout@4056c4f8

m_Canvas.Initialize(m_Panel.getObject()); throws this Error:

java.lang.NullPointerException
main_activity_create (B4A line: 24)
m_Fader.Initialize(Activity, "Fader")
java.lang.NullPointerException
at anywheresoftware.b4a.objects.drawable.CanvasWrapper.Initialize(CanvasWrapper.java:71)
at anywheresoftware.b4a.sample.FirstLib.Initialize(FirstLib.java:48)
at com.uhs.test.main._activity_create(main.java:224)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:105)
at com.uhs.test.main.afterFirstLayout(main.java:84)
at com.uhs.test.main.access$100(main.java:16)
at com.uhs.test.main$WaitForLayout.run(main.java:72)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException
CREATE SURFACE Surface(name=com.uhs.test/com.uhs.test.main, identity=2610, mNativeSurface=0) IN SESSION android.view.SurfaceSession@40a42ee0: pid=26283 format=-2 flags=0x0 / Window{40974670 com.uhs.test/com.uhs.test.main paused=false}
Window Window{4086ceb8 com.uhs.test/com.uhs.test.main paused=false} destroyed surface Surface(name=com.uhs.test/com.uhs.test.main, identity=-1, mNativeSurface=0), session Session{40844dd0 uid 10118}
com.uhs.test/com.uhs.test.main[2609] is not removed from mLayerMap

What's wrong here?
 
Last edited:
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
Panels in panels with views Oh My !!!

You can create custom user controls however not add them with the designer. You can put a Panel instead of the custom control and then programmatically place the control in the Panel.

Perhaps I'm misunderstanding you. Firstly I APPRECIATE YOUR ASSISTANCE THANK YOU !!!!! :sign0188:

You said -->
A Custom UserControl can be added to a panel programmatically ?

As I understand it :sign0104: in Basic4Android a "customcontrol" consists of a panel with views on it. I add the VIEW a panel programatically to my activity and load layout on the panel of my already grouped controls.. but this seems wrong to me since I need to have multiple panels which actually represent many CustomUserControls.

So I THINK your saying I Add the View(panel) programmatically then programmatically load more views into this panel instead of loadlayout into the panel.

kanaida said I should make my nested panels children of the activity not of the panel that exists as the base of the Grouped controls.
This is even more confusing.. as I will need to iterate over all of the views inside my panel (sub) which is representing a usercontrol and this panel (sub) sits along with many more inside of another panel (Master-Alpha) which may need to be (swapped out) for some other bucket (Master-Beta panel) which is holding yet again its own little buckets (Subs) of views..

Honestly As I review my maddness above I have omitted at least one level of panel depth in my description :BangHead::BangHead::BangHead::BangHead::BangHead:


I'm soo confused !!!! :BangHead: :BangHead: :(

Perhaps you are saying that I can fill my panel with these little disparate views (labels n such) and "pretend" that its a control ......but actually I have to iterate the panel's contents and affect changes manually on all of the views inside of it... manually .. to make it "act" like they were tied together in a control. Is this correct ? My 2 cents == that's not a customUserControl that is me writing TONS of graphic interface changes to update TONS of little views that just happen to be sitting on the same panel

Please understand I am just trying to understand this better I don't mean to appear rude I am assuredly very new to Basic4Android and GREATLY appreciate any and all assistance...

It is going to be quite the experience attempting to replicate the functionality in this Windows app with Basic4Android:: Attachment Image "Main Form"

Almost everything on this crowded little form is a complex custom user control background color changes flyout menus .. Custom controls buried within more custom controls
 

Attachments

  • MainForm..JPG
    MainForm..JPG
    95.6 KB · Views: 417
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It shouldn't be too difficult to create a "custom view" made by grouping several views.

Here is a very simplistic implementation:
Code module named C1
B4X:
Sub Process_Globals
   Type MyView (p As Panel, b1 As Button, l1 As Label)
End Sub

Sub CreateMyView(ButtonEvent As String, ButtonText As String, LabelText As String) As MyView
   Dim m As MyView
   m.Initialize
   m.p.Initialize("")
   m.b1.Initialize(ButtonEvent)
   m.b1.Text = ButtonText
   m.l1.Initialize("")
   m.l1.Text = LabelText
   m.b1.Tag = m 'store the structure in the button's Tags property.
   m.p.AddView(m.b1, 10dip, 10dip, 100dip, 40dip)
   m.p.AddView(m.l1, 10dip, 50dip, 100dip, 40dip)
   Return m
End Sub

Sub ChangeValue(m As MyView, value As String)
   m.l1.Text = value
End Sub

Activity:
B4X:
Sub Process_Globals

End Sub

Sub Globals
   Dim m1, m2 As MyView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   m1 = c1.CreateMyView("m1", "Button #1", "Label #1")
   Activity.AddView(m1.p, 10dip, 10dip, 100dip, 200dip)
   m2 = c1.CreateMyView("m2", "Button #2", "Label #2")
   Activity.AddView(m2.p, 10dip, 110dip, 100dip, 200dip)
End Sub

Sub m1_Click
   c1.ChangeValue(m1, "new value")
End Sub

Sub m2_Click
   c1.ChangeValue(m2, "new value2")
End Sub
 
Upvote 0

kanaida

Active Member
Licensed User
Longtime User
Sorry for the confusion.

Basically in vb/.net user controls are classes, in b4a those don't really exist yet. It's sorta-object oriented-ish. That's why it seems very complex to lay things out sometimes, at times there's a ton of variables to deal with so we have to work out ways of keeping track of objects.

to simulate what a user control is, we need a sub to create those things are erel shows above.
but to access items in that control isn't as easy as Panel1.Label.text = "2323", we have to remember variable names, and stuff like that.

What i've been doing lately to help remedy this is declaring new types to hold stuff more easily. It's a workaround at least.

Type TYPE_USERCONTROL_SOMENAME(L1 as label, T1 as textbox, etc...)

Sub NewSomeName(Maybe some vars here to init) as TYPE_xxxxxxx
Dim x as TYPE_xxxxxxxxxx
x.L1.initialize()
x.T1.initialize()
return x
End Sub

I posted a sample project by the way. I had all the same exact questions when I started too. Took some hammering to get into my head that View = Control, and Spinner = Combobox.
 
Upvote 0
Top