Add counter to TableViewRow

You must Login before you can answer or comment on any questions.

Hi there. I need to create custom table row with label, counter and right arrow (using hasChild property). Like on this picture.

I tried to do this with following code:

var data = [];
for (var item in items) {
    var tableRow = Ti.UI.createTableViewRow({
        layout: 'horizontal',
        hasChild: true
    });
 
    var text = Ti.UI.createLabel({
        text: items[item].text,
        width: 'auto',
        textAlign: 'left'
    });
 
    var counter = Ti.UI.createLabel({
        text: items[item].count,
        width: 'auto',
        textAlign: 'right',
        backgroundColor: '#ccc',
        borderRadius: 5
    });
 
    tableRow.add(text);
    tableRow.add(counter);
    tableRow.className = 'some_row';
 
    data.push(tableRow);
}
 
list= Ti.UI.createTableView({data: data});
 
window.add(list);
On Android it looks awfully:

  1. Both lables are left aligned and I need "counter" label to be right aligned.
  2. counter's background isn't smooth.

So can anyone help me to make such nice control?

— asked 1 year ago by Paul Annekov
1 Comment
  • Does anybody know how this control is called in iOS or how to make it in Xcode? Or maybe somebody know how to implement it using Titanium?

    — commented 1 year ago by Paul Annekov

2 Answers

instead of using "text align" if would be better to place them with left and right properties

Try this:

var counter = Ti.UI.createLabel({
        text: items[item].count,
        width: 'auto',
        left: '50%', // Can be % or fixed value
        backgroundColor: '#ccc',
        borderRadius: 5
});
Best,

Minh

— answered 1 year ago by Minh Nguyen
answer permalink
3 Comments
  • Label position changed. But now label's left side is just after parent's center point. It isn't what I need. Counter must be placed just before arrow.

    — commented 1 year ago by Paul Annekov

  • Adjust left value to archive what you need, .i.e left: '80%'

    — commented 1 year ago by Minh Nguyen

  • As you see on this screenshot second label moved to next line, because it has one additional symbol. So setting left property using percents isn't good.

    — commented 1 year ago by Paul Annekov

Your Answer

Think you can help? Login to answer this question!