Editable and moveable text in a panel

artiechappie

Member
Licensed User
Longtime User
Hi Guys,

It's been a few years since I did any development in VB and I must say, with the little bits I've been doing with Basic4Android, I'm seriously impressed so well done guys!! On this basis, I would class myself as a Newbie!!

OK to my question:

I am designing a small app to create and order signs/badges/business cards etc. and I've come a fair way. However, what I would like to do is create text lines within a panel which contains the layout in terms of size etc. and be able select a font type and, if possible, drag this into position on the sign/badge layout.

So for example Line 1 is in Bold Arial font, size 16 for example and can be dragged/placed at the top of the layout and line 2 in in Arial narrow font size 14 and again can be freely placed on the layout.

Ideal would also to be able to add in logos, artwork etc. and place these on the layout too.

Currently I'm using EditText Objects for each line, but this is a bit limiting in terms of placement, font selection etc

Any ideas anyone?

Many thanks on advance.
 

artiechappie

Member
Licensed User
Longtime User
OK - I think I've found a way of making the text "draggable" and visible within a panel. What I need to do though is - as I enter text into the EditText box, I want this to update the Label text within the panel. I should then be able to move this around and place it wherever I need it on the panel.

I've used your suggested "Creating a view programatically" as a basis for my trial, but any suggestions for doing the above would be much appreciated.

Here is my code so far:

'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim lblTitle, lblPanelTitle As Label
Dim pnlTest As Panel
Dim btnTest As Button
Dim TextBox As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
lblTitle.Initialize("")
lblTitle.Color = Colors.Red
lblTitle.TextSize = 20
lblTitle.TextColor = Colors.Blue
lblTitle.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL
lblTitle.Text = "Title"
Activity.AddView(lblTitle, 20%x, 10dip, 60%x, 30dip)

TextBox.Initialize("")
TextBox.Color = Colors.White
TextBox.TextSize = 20
TextBox.TextColor = Colors.Black
TextBox.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
TextBox.Hint = "Enter Your Text Here"
Activity.AddView(TextBox, 0, 50dip, 300dip, 40dip)



pnlTest.Initialize("")
pnlTest.Color = Colors.Blue

btnTest.Initialize("btnTest")
btnTest.Text = "Test"

lblPanelTitle.Initialize("")
lblPanelTitle.Color = Colors.Red
lblPanelTitle.TextSize = 16
lblPanelTitle.TextColor = Colors.Blue
lblPanelTitle.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL
lblPanelTitle.Text = "Panel test"

Activity.AddView(pnlTest, 0, lblTitle.Top + lblTitle.Height + TextBox.Top + TextBox.Height + 10dip, 100%x, 50%y)
pnlTest.AddView(lblPanelTitle, 20dip, 10dip, 100dip, 30dip)
pnlTest.AddView(btnTest, 50dip, 50dip, 100dip, 60dip)

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


... any tips on how to do this would be great.

Thanks
 
Upvote 0

artiechappie

Member
Licensed User
Longtime User
..... and I've used the button to update the Label text as below:

Sub BtnTest_CLICK


lblPanelTitle.Text = TextBox.Text


End Sub

This works OK but automatic updating would be nice.
 
Upvote 0

admac231

Active Member
Licensed User
Longtime User
B4X:
Sub TextBox_TextChanged (Old As String, New As String)
      lblPanelTitle.Text = New
End Sub

You'll also have to change TextBox.Initialize("") to TextBox.Initialize("TextBox"). The part in quotes determines the prefix for the methods.

So if you had TextBox.Initialize("myText") you would use:
B4X:
Sub myText_TextChanged (Old As String, New As String)
      lblPanelTitle.Text = New
End Sub


Edit: Also, here's a fairly good panel_touch event if you need it. It keeps the label in the middle of the finger and keeps it within the boundaries of the panel.
B4X:
Sub pnlTest_Touch (Action As Int, X As Float, Y As Float)
   X = X-(lblPanelTitle.Width/2)
   Y = Y-(lblPanelTitle.Height/2)
   If x >= 0 AND x <= pnlTest.Width-lblPanelTitle.Width Then
      lblPanelTitle.Left = X
   End If
   If y >= 0 AND y <= pnlTest.Height-lblPanelTitle.Height Then
      lblPanelTitle.Top = Y      
   End If
End Sub
 
Last edited:
Upvote 0

artiechappie

Member
Licensed User
Longtime User
Great help - many thanks. Worked like a dream!!

All I need to do now i figure out how to move the LabelText around within the panel.

Any help for this newbie to Basic4Android would be much appreciated.

Thanks again
 
Upvote 0

artiechappie

Member
Licensed User
Longtime User
Hi Admac231,

I couldn't get your code for moving the panel Labeltext to work - sorry but thanks for trying.

The label stays where it is.
 
Upvote 0
Top