Android Question [Solved]Unknown member in CustomView

Theera

Well-Known Member
Licensed User
Longtime User
I have coded as belows,mBase doesn't knows the member 'HasLogo'
B4X:
#DesignerProperty: Key: HasLogo,DisplayName: MyLogo,FieldType: Boolean,DefaultValue:False,Despcription: There is Logo Icon ,or not
In Class_Globals Module
B4X:
Public m_HasLogo As Boolean=False
In DesignerCreateView Module
B4X:
m_HasLogo=Props.GetDefault("HasLogo",False)
'In Part of Coding Module
B4X:
Public Sub setHasLogo(HasLogo As Boolean)
   m_HasLogo=HasLogo
   mBase.??
 
Solution
Just to clarify:
mBase is not the CustomView, it is the main Panel of the CustomView, nothing else.
The properties of mBase are the same as for any other B4XView, you cannot add other properties.
CustomView properties set with setMyProperty and / or getMyProperty routines in the CustomView Module are Properties accessible from outsides the CustomView Module where the CustomView is declared.

You could use Public variables too to change their values from outsides the CustomView module.

When should we use a Public variable instead of a Property ?
You can change the value of a Public variable from outsides, but this does only change the value and nothing else.
But, when you change a value from outsides and you need to do something in...

Sagenut

Expert
Licensed User
Longtime User
m_HasLogo is your Global Variable.
HasLogo is the parameter passed to the sub.
They are not properties or methods of mbase.
What are you trying to obtain?
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
m_HasLogo is your Global Variable.
HasLogo is the parameter passed to the sub.
They are not properties or methods of mbase.
What are you trying to obtain?
Is there way to add hasLogo property in CustomView?
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Your variable m_HasLogo contain the value.
As you have already done here
B4X:
m_HasLogo=Props.GetDefault("HasLogo",False)
and here
B4X:
Public Sub setHasLogo(HasLogo As Boolean)
   m_HasLogo=HasLogo 'And here
   mBase.??
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Your variable m_HasLogo contain the value.
As you have already done here
B4X:
m_HasLogo=Props.GetDefault("HasLogo",False)
and here
B4X:
Public Sub setHasLogo(HasLogo As Boolean)
   m_HasLogo=HasLogo 'And here
   mBase.??
B4X:
Public Sub setHasLogo(HasLogo As Boolean)
   m_HasLogo=HasLogo 'And here
   mBase.HasLogo=HasLogo
mbase unknow HasLogo , how do I do? I'msorry I can't explain my problem.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
mbase unknow HasLogo , how do I do? I'msorry I can't explain my problem.
Maybe I understood what you are searching for.
Go to the Main.
In there you should have declared your CV (QrCodePromptPay?).
In Main you can do
B4X:
QrCodePromptPay.HasLogo
Check this.
But inside your CV, the code where you are now, it will simply be your variable.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Since you declared m_HasLogo as public, you can eliminate the Sub setHasLogo.
Instead, in your CV property to give it the image, which I assume is called setLogo, in this you will put m_HasLogo = True

I would change the name of m_HasLogo to HasLogo.
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Hi Both,
Since I had no experience creating CustomViews before and didn't speak English very well as the two of you explained, I was confused about how many times I wanted to learn from the examples of how to create CustomViews. Sometimes it makes others mistakenly think that they are just waiting for an answer. Do not do it yourself. Listening to the words makes me feel bad. (Google translate)
 

Attachments

  • QRCodePromptPay.zip
    11 KB · Views: 5
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
B4X:
#DesignerProperty: Key: HasLogo,DisplayName: MyLogo,FieldType: Boolean,DefaultValue:False,Despcription: There is Logo Icon ,or not
Maybe I understood that the above code, it doesn't define member of mbase to know its has. (HasLogo is the one of member of mBase)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4X:
#DesignerProperty: Key: HasLogo,DisplayName: MyLogo,FieldType: Boolean,DefaultValue:False,Despcription: There is Logo Icon ,or not
(HasLogo is the one of member of mBase)
That line creates the HasLogo property for your custom view in the Designer, mBase is just the bottom panel of the CV.

I think you should not write that line, the programmer who will use your custom view should not have the ability to set HasLogo in the Designer, HasLogo should be True when he will pass a B4XBitmap to your View.
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
I have read Klaus'customview compare with BooleanExample.Why it can be done?
 

Attachments

  • Screenshot_20250121_122021.png
    Screenshot_20250121_122021.png
    275.7 KB · Views: 14
  • Screenshot_20250121_121928.png
    Screenshot_20250121_121928.png
    157.5 KB · Views: 14
  • Screenshot_20250121_121953.png
    Screenshot_20250121_121953.png
    152.6 KB · Views: 13
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
After I have tried as follows Klaus'example , there is hasLogo 's property, but Why does't create Public Sub seHasLogo(HasLogo As Boolean) like others i.e. Enabled, Visibled
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Thank you ,all of you and sorry you to make terrible.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Just to clarify:
mBase is not the CustomView, it is the main Panel of the CustomView, nothing else.
The properties of mBase are the same as for any other B4XView, you cannot add other properties.
CustomView properties set with setMyProperty and / or getMyProperty routines in the CustomView Module are Properties accessible from outsides the CustomView Module where the CustomView is declared.

You could use Public variables too to change their values from outsides the CustomView module.

When should we use a Public variable instead of a Property ?
You can change the value of a Public variable from outsides, but this does only change the value and nothing else.
But, when you change a value from outsides and you need to do something in the CustomView module depending on the new value with some code, then you must use a Property.

I had a look at your project and have some comments.
In your first post you declared:
B4X:
Public m_HasLogo As Boolean=False
A property should not be declared as Public but as Private, in the Class_Global routine.
In your project in post#8 you declare it as Private, which is OK, but you should move the line form the DesignerCreateView routine to the Class_Global routine.
But, then the question: When the value of m_HasLogo is changed from outsides, do you need to do something with code in the CustomView module ?
If yes, use a Property like this:
B4X:
Public Sub setHasLogo(HasLogo As Boolean)
    m_HasLogo = HasLogo
    If m_HasLogo = False Then
        'code for m_HasLogo = False
    Else
        'code for m_HasLogo = True
    End If
End Sub
If no just use a Public variable, but in that case i would name it simply HasLogo.

You declare these B4XViews in Class_Globals:
B4X:
    Private mQRCodePromptPay As B4XView
    Public mLbl As B4XView
    Public mPnlUpper As B4XView
Are you sure you want to have those Public, which means accessible from outsides.
If yes OK.
If no set them as Private.
You add these views onto mBase in DesignerCreateView.
B4X:
mBase.AddView(mQRCodePromptPay,0,0,0,mBase.Height)
mBase.AddView(mLbl,0,0,mBase.Width,mBase.Height)
mBase.AddView(mPnlUpper,0,0,mBase.Width,mBase.Height)
What is the purpose of mQRCodePromptPay with a Height of 0 ?
You set mLbl as Lbl form
B4X:
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
  mBase = Base
  Tag = mBase.Tag
  mBase.Tag = Me
    
    mLbl = Lbl
You cannot use this label.
You need to declare a new one.
You set their dimensions to wth with and height of mBase, this means that they are covering each other !?

You have declared several properties with DesignerProperty and Props.GetDefault like:
B4X:
#DesignerProperty: Key: HasLogo, DisplayName: HasLogo, FieldType: Boolean, DefaultValue: False,Description: There is logo Icon
m_HasLogo = Props.GetDefault("HasLogo",False)
Do you really need properties ?
If yes, do you want that the user of the CustomView can set their values in the Designer.
If yes, that is OK.
If no, you do not need this.
You try to declare this:
B4X:
#DesignerProperty: Key: Logo, DisplayName: Logo, FieldType: Bitmap, Description: Add Logo bitmap
But FieldType Bitmap does not exist !

Attached your project modified.

Another suggestion:
Your project is a B4XPages project with a well defined structure.
To maintain this structure you should not zip it with File / Export As Zip but clicking on this line on top of the B4xMainPage module.
1737464071038.png

The problem with your project from post#8 is that the first line
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
throughs an error and must be commented because the Shared Files folder does not exist.

To have access to your CustomView, you need to add it in the Designer in the layout.
This is not yet the case in your project.
 

Attachments

  • QRCodePromptPayNew.zip
    12.3 KB · Views: 7
Upvote 0
Solution
Top