0

What I am trying to do is create a set of buttons for each row found in my SQLite database. I am testing this on the iPad simulator. Using titanium SDK 2.1.4

Here is what I have:

var currentWin = Ti.UI.currentWindow;

var db = Ti.Database.install('../databasename.sqlite', 'table'); //Install SQLite Database
var rows = db.execute('SELECT DISTINCT row FROM table');



var brandView = Ti.UI.createView({   //Primary view for buttons
        title: 'Hello',
        width: '100%',
        height: '100%'
});
currentWin.add(brandView);

for(var j = 0; j < rows.length; j++) {   //Pull DB Info
var buttonCount = new Array(rows.length);   //Create Button names
for(var i = 0; i < buttonCount.length; i++) {
    buttonCount[i] = Ti.UI.createButton({
        title: rows[j].name,
        width: 100,
        height: 100
    });
    brandView.add(buttonCount[i]);
}
}

It loads without any error, and loads the window, and the view I am calling but no buttons. How can I create a group of buttons based on the retrieved database info?

1 Answer 1

1

I don't really understand your use of the buttonCount array or your two for loops. Will this work?

for(var j = 0; j < rows.length; j++) {
    var btn = Ti.UI.createButton({
        title: rows[j].name,
        width: 100,
        height: 100,
        top: j * 105 // space the buttons at 105
    });
    brandView.add(btn);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.