Help please

74 views
Skip to first unread message

john Oneplus

unread,
May 12, 2022, 1:39:24 AM5/12/22
to DroidScript
Hello

I've been pulling my hair out!

How can I set the text to display but in different lines? (New line but gets the data from read file and inserts the data singulary on a new line? 



//Called when application is started.
function OnStart()
{

app.GetPrivateFolder( "","external" ) 
 //Create a layout with objects vertically centered.
 lay = app.CreateLayout( "Linear", "VCenter,FillXY" )


    app.WriteFile( "taskMania.txt", "\n", "Append" );

    var txt = app.ReadFile("taskMania.txt");
   // var length = txt.split("\n").length;
   var length = txt.split("\n");
   
  // app.ShowPopup("myFile contains " + length + " lines");
alert(txt)



getInput1 = prompt("Enter task");
  app.WriteFile( "taskMania.txt", getInput1,"Append" );

 app.ReadFile("taskMania.txt");
alert(getInput1)

 //Create a text label and add it to layout.
var txt2 = app.CreateText(txt,"MultiLine","Html")  //WANT TO INSERT INPUT DATA INTO NEW A NEW LINE BUT NOT WORKING
 txt2.SetTextSize( 10 )
 lay.AddChild( txt2 )
// txt2 = txt.replace(/\n/g,"")
 txt2.SetText( txt.split("\n" ));
  

 //Add layout to app. 
 app.AddLayout( lay )
}

Steve Garman

unread,
May 12, 2022, 2:51:22 AM5/12/22
to DroidScript
You appear to be mixing html and plain text
newline characters do not display in html

Try removing the "Html" option from app.CreateText to see what is happening

Steve Garman

unread,
May 12, 2022, 2:55:30 AM5/12/22
to DroidScript
If your text is html, you may need to add "<br>" instead of "\n" 

john Oneplus

unread,
May 12, 2022, 11:54:31 AM5/12/22
to DroidScript
Hi

Thanks for your reply.

I will try this tonight and let you know how I get on.

Kind Regards 

john Oneplus

unread,
May 12, 2022, 11:59:15 AM5/12/22
to DroidScript
Hi,

The list is still showing on 1 line.



//Called when application is started.
function OnStart()
{

app.GetPrivateFolder( "","external" ) 
 //Create a layout with objects vertically centered.
 lay = app.CreateLayout( "Linear", "VCenter,FillXY" )


    app.WriteFile( "taskMania.txt", "\n", "Append" );

    var txt = app.ReadFile("taskMania.txt");
   // var length = txt.split("\n").length;
   var length = txt.split("\n");
   
    app.ShowPopup("myFile contains " + length + " lines");
alert(txt)



getInput1 = prompt("Enter task\n");
  app.WriteFile( "taskMania.txt", getInput1,"Append" );

 app.ReadFile("taskMania.txt");
alert(getInput1)

 //Create a text label and add it to layout.
 txt = app.CreateText(txt,"MultiLine")
 txt.SetTextSize( 10 )
 lay.AddChild( txt )
 //Add layout to app. 
 app.AddLayout( lay )
}

Alan Hendry

unread,
May 12, 2022, 12:28:19 PM5/12/22
to DroidScript
HI,

Typing this in here, so there may be typos etc

The code seems to append \n to taskmania.txt, read it into variable txt, (split and display line count - what does it show?)
prompt into getinput, append that to the file, I think it should next read into variable txt
txt = app.ReadFile("taskMania.txt");
You don't have <br> for new lines, so "Html" should be omitted,  
and width/height can't be omitted (null or -1 to let contents set size)
var txt2 = app.CreateText(txt,-1,-1,"MultiLine")
(If it was html the parameter would be one string "MultiLine,Html")

Also PrivateFolder isn't used, but it should be something like this
gpf = app.GetPrivateFolder( "","external" ) 
 
Regards, ah

john Oneplus

unread,
May 12, 2022, 2:28:52 PM5/12/22
to DroidScript
Hello

Thank you so much everyone, this has resolved the issue.

Thank you, I'm learning all of this and I'm not very quick at it:-)

This is now resolved.

I probably will require a lot more help in time, I do try and look online first though hehe.

Reply all
Reply to author
Forward
0 new messages