display a comma on a list view

262 views
Skip to first unread message

Netpower8

unread,
Jul 11, 2016, 7:09:14 AM7/11/16
to DroidScript
Is there a way to display a comma on a list view? The comma is also a delimeter seperator for the list. Is there a command to set the comma as a comma not a delimeter. Thanks for the reply

Charles Wilt

unread,
Jul 11, 2016, 7:27:30 AM7/11/16
to DroidScript
Yes. First build your list as a string using a different delimeter.
Use SetList( list, delimeter ).

Netpower8

unread,
Jul 11, 2016, 8:30:34 AM7/11/16
to DroidScript
Thank you very much. This has been bothering me for some time

Christian Höhne

unread,
Aug 2, 2016, 4:54:17 AM8/2/16
to DroidScript
Hi Charles, this is my first post.
I am not able to display in a ListView items having a comma (I mean the full screen ListView, not a List). The solution you propose works for a List but not for a ListView.
Can you please post a working example that shows how to create a ListView with items separated by a custom delimiter, other than the comma?

This is my sample test script:

//Called when application is started.
function OnStart()
{
    var data = "Hi, Joe%how are you?";
    lay = app.CreateLayout( "linear", "VCenter,FillXY" ); 

    // this shows two lines (not what I want):
    // Hi
    // Joe%how are you?
    lvw1 = app.CreateListView(data);

    // ...so I create a standard list with custom delimiter
    // which displays the two lines that I want:
    // Hi, Joe
    // how are you?
    lst = app.CreateList();
    lst.SetList(data,"%");
    lay.AddChild(lst);
    app.AddLayout(lay);

    // now I try to assign this list to a new ListView
    // but the result is [object Object]
    lvw2 = app.CreateListView(lst);
}

BTW, reading the documentation on ListView methods at http://wiki.droidscript.me.uk/doku.php?id=built_in:lists after the examples, I noticed that many of them don't work; I tried ListView.AddItem, ListView.GetLength, ListView.InsertItem and few others: they exist for List but not for ListView, contrary to what the methods table claims. For example, The Debug log says "Script Error: Object has no method 'AddItem', Line 7, sample.js.".

Regards

Steve Garman

unread,
Aug 2, 2016, 7:01:22 AM8/2/16
to DroidScript
Christian,
On the wiki comment, the page you linked to is the page about the List control, not the ListView, which is at http://wiki.droidscript.me.uk/doku.php?id=built_in:listview

It is a historical accident that list control referred to on the List page has been named ListView. That should probably be changed.

As regards your question about putting commas in a ListView, the simple fact seems to be that it cannot be done.

If you need something that looks/acts like a ListView, you will probably need to create a custom dialog.

I will post a sample function
myListView
in a couple of minutes.

Steve Garman

unread,
Aug 2, 2016, 7:04:46 AM8/2/16
to DroidScript

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

// myListView can take list,title,callback
lvw1= myListView("aaa,bbb,ccc","my title",lvw1_OnTouch);
lvw1.Show();

// this is more like what you are looking for

var data = "Hi, Joe%how are you?";

lvw2 = myListView();
lvw2.SetList(data,"%");
lvw2.Show();

}

function lvw1_OnTouch(item,body,icon,index)
{
app.ShowPopup(item);
lvw1.Dismiss();
}

function myListView(list,title,callback)
{
var lv = app.CreateDialog( title,"noXcancel" );
var lay = app.CreateLayout( "Linear", "" );
var lst = app.CreateList( list,1,1 );
lay.AddChild( lst );
lv.AddLayout( lay );
if(callback) lst.SetOnTouch( callback );
else lst.SetOnTouch(_Cb(lv,"dfltCb"))

lv.dfltCb=function()
{lv.Dismiss();}

lv.SetList = function(list, delim)
{
lst.SetList(list, "%");
}
return lv
}

Christian Höhne

unread,
Aug 2, 2016, 12:11:00 PM8/2/16
to DroidScript
Thanks Steve, your help was precious, I could use your sample in my project, and it works. So, the idea is to use a standard List instead of a ListView, but show it in a dialog that shows full screen and that can be dismissed. Great!
Thanks.
Christian 

Steve Garman

unread,
Aug 2, 2016, 1:28:54 PM8/2/16
to DroidScript
Thanks for the feedback Christian.

It is always good to know someone has understood the code and not just pasted it.

Juan Jo

unread,
May 22, 2017, 2:49:02 PM5/22/17
to DroidScript
bit late to this but that really bugged me, found the html encoding of a comma so you use the html as your type for the create layout


BTW anyone, is there more options for lists other than these default lists? 

function OnStart()
{
    //Create a layout with objects vertically centered.
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );    
 
    //Create a list and add it to layout.
    var data =
    "<font color='#ff0000'>Red&#44;comma here</font>,"+
    "<font color='#00ff00'>Green</font>,"+
    "<font color='#0000ff'>Blue</font>"
    lst = app.CreateList( data,-1,-1,"html" );
    lay.AddChild( lst );
    
    //Add layout to app.    
    app.AddLayout( lay );
}
Reply all
Reply to author
Forward
0 new messages