Android Question Change designer property in code

devmobile

Active Member
Licensed User
Hello
I make customview and use it.
I need change property of customview sometime with code
but i cannot access it
 

devmobile

Active Member
Licensed User
You need to define these properties in the CustomView class.
Have a look at chapter 4.3 Add properties in the B4x CustomViews booklet (link in my signature).
I know
But i define property(filename) in designer that when i use it,it load picture from asset with property filename
Now i need set filename with code after load it in layout and it is error because the designer property priority is high
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Can you post some code, specially the part related to the filename prop so that we can help?
 
Upvote 0

devmobile

Active Member
Licensed User
I attach my library(i try make it for show svg viewer in designer)
I this library or customview,i enter svg filename exist in DirAsset and enter it in designer
And when load layout,my class load svg file
Now
I need enter filename with code not designer
Maybe?
 

Attachments

  • SVG Viewer.zip
    6.2 KB · Views: 159
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
which svg library are you using?
I need to download it in order to test your CV
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
As I said: You need to define these properties in the CustomView class.
You need to add in the class code routines defining properties accessible from outsides.

Add two local variables in the class:
Private mFilePath, mFileName As String

The code below adds the FilePath and FileName and FilePath properties:
B4X:
'set or get the FilePath property
Public Sub setFilePath(FilePath As String)
    mFilePath = FilePath
End Sub

Public Sub getFilePath As String
    Return mFilePath
End Sub

'set or get the FileName property
Public Sub setFileName(FileName As String)
    mFileName = FileName
End Sub

Public Sub getFileName As String
    Return mFileName
End Sub

Or as a subroutine where you can change both in the same routine:
B4X:
'set the FilePath and FileName
Public Sub SetFilePathAndName(FilePath As String, FileName As String)
    mFileName = FileName
    mFilePath = FilePath 
End Sub

Example in the Main module:
B4X:
Log(SVGViewer1.FilePath)
Log(SVGViewer1.FileName)
SVGViewer1.SetFilePathAndName(File.DirRootExternal, "MyFile.svg")
Log(SVGViewer1.FilePath)
Log(SVGViewer1.FileName)

It's up to you to add the code to do what you need with FilePath and FileName.

Attached a modified version.
 

Attachments

  • SVG Viewer1.zip
    10.9 KB · Views: 154
Upvote 0

devmobile

Active Member
Licensed User
Thanks my friend
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…