XMLBuilder issue

giga

Well-Known Member
Licensed User
Longtime User
Strange Problem,

I am using the XMLBuilder library and was able to get the EditText1.text to write into an .xml file. It stopped working and is showing "" in the xml for the profile="" and not the user input.

B4X:
 Dim x As XMLBuilder 
x = x.create("maps") 
x = x.element("string_name") _ 
.attribute("profile",EditText1.text) _
.element("timestamp") _ 
.attribute("time", "date") _ 
.up() _     
.element("maps") _ 

Dim props As Map
 props.Initialize
 props.Put("indent", "yes")
File.WriteString(File.DirRootExternal, "sync.xml", x.asString2(props))

Thanks for the help:)
 

giga

Well-Known Member
Licensed User
Longtime User
Check the value of EditText1.text:
B4X:
Log("EditText1: " & EditText1.Text)

I guess that you will see that it is empty.

Yes it is empty,

However the user types in the EditText1 and clicks save profile button
the log for EditText1 shows empty.
But the xml is created.

I had this working before.:sign0148:

Here is the code:

B4X:
Sub SaveINI_Click()

EditText1.initialize("EditText1")
 
 Dim x As XMLBuilder 
x = x.create("maps") 
x = x.element("string_name") _ 
.attribute("profile", EditText1.Text) _  
.element("timestamp") _ 
.attribute("time", "date") _ 
.up() _   
.element("maps")

 Log("EditText1: " & EditText1.Text)
 
Dim props As Map
 props.Initialize
 props.Put("indent", "yes")
 File.WriteString(File.DirRootExternal, "profile.xml", x.asString2(props))
 ToastMessageShow ("Profile Saved", True)

 

End Sub

Thanks for the Help As Always
 
Upvote 0

giga

Well-Known Member
Licensed User
Longtime User
You must remove this line in the subroutine:
B4X:
EditText1.initialize("EditText1")
You are creating a new instance of the EditText1 and of course it's empty.

Best regards.

Klaus,

Thanks for the reply. I have removed the :
B4X:
EditText1.initialize("EditText1")
from the subroutine and I am back to the error that Edittext needs to be initialized.

Could this be a layout problem?
:BangHead: Periodically when I am opening the project it asks for a Layout Name.
But I have the
B4X:
 Sub Activity_Create(FirstTime As Boolean)  
Activity.LoadLayout("main")
How do I check that?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Where do you define EditText1 ?

If you define it in a layout file you need in Globals :
Dim EditText1 As EditText

If you define it in the code you need in Globals :
Dim EditText1 As EditText
Then in Activity_Create :
EditText1.Initialize("EditText")
Activity.AddView(EditText1, 10dip, 10dip, 150dip, 60dip)

The dimensions are just an example.

Unfortunatley with just a small code snippet and without seeing the rest of the project it's difficult to help.

Best regards.
 
Upvote 0

giga

Well-Known Member
Licensed User
Longtime User
Klaus,

I respect and appreciate your expertise.

I defined Dim EditText1 As EditText under Globals.
But I did not put it under Activity create. I will try that and see if it solves the issue and post the results.

If I need more than one EditText under one subroutine. Can I do this code?

EditText1.Initialize("EditText")
EditText2.Initialize("EditText")
EditText3.Initialize("EditText")
Activity.AddView(EditText1, EditText2, EditText3)


Thanks,
 
Upvote 0

giga

Well-Known Member
Licensed User
Longtime User
Please disregard this bad code Activity.AddView(EditText1, EditText2, EditText3)

strangely when I try to compile the project it keeps asking to save layout, When in fact I have not made a new layout.

If I click cancel it compiles but still does not work.

Thanks,[/QUOTE]
 
Upvote 0

giga

Well-Known Member
Licensed User
Longtime User
Klaus,:sign0162:

Thanks for the tip. This worked Activity.AddView(EditText1, 10dip, 10dip, 150dip, 60dip)

The problem was I had the boxes already created through AddView and it was not linking to XML Builder. By placing the dips in it is working now. :sign0060:

RESPECT
 
Upvote 0
Top