首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >钛Android -在SQLITE数据库中导航记录

钛Android -在SQLITE数据库中导航记录
EN

Stack Overflow用户
提问于 2013-11-02 04:51:53
回答 1查看 362关注 0票数 1

我只是想弄清楚如何使用简单的“前进”和“后退”按钮在sqlite数据库中的记录之间导航。

我可以访问数据库并显示记录--我通过创建记录的表视图来实现这一点,然后如果单击记录,它会显示更多的详细信息。然后,我只想让这个页面上的按钮在数据库中导航。

我不知道需要对按钮应用什么代码。

这是窗口的代码。

代码语言:javascript
复制
// create var for the currentWindow
var currentWin = Ti.UI.currentWindow;
var id = currentWin.id;


function photoGalleryDidClose(item) {
photoView.image = item.media;
}


var db = Titanium.Database.open('photos');

var sql = db.execute('SELECT * FROM photos where id=?', currentWin.id);

var recordID = sql.fieldByName('id');
var title = sql.fieldByName('title');
var location = sql.fieldByName('location');
var photographer = sql.fieldByName('photographer');
var equipment = sql.fieldByName('equipment');
var caption = sql.fieldByName('caption');
var notes = sql.fieldByName('notes');
var date = sql.fieldByName('date');
var imageUrl = sql.fieldByName('imageUrl');


//Labels to display catalogue details

var labelrecordID = Titanium.UI.createLabel({
    text:'Record ID:',
    font:{fontSize:18},
    top:30,
    left: 10,
    height: 25,
    width:'auto'
})
currentWin.add(labelrecordID);

var labelrecordID1 = Titanium.UI.createLabel({
    text:'  '+ recordID +'',
    font:{fontSize:18},
    color:'black',
    borderRadius: 2,
    top:30,
    left: 150,
    height: 25,
    backgroundColor:'white',
    width:'300'
})
currentWin.add(labelrecordID1);


var labelTitle = Titanium.UI.createLabel({
    text:'Title:',
    font:{fontSize:18},
    top:70,
    left: 10,
    height: 25,
    width:'auto'
})
currentWin.add(labelTitle);

var labelTitle1 = Titanium.UI.createLabel({
    text:'  '+ title +'',
    font:{fontSize:18},
    color:'black',
    borderRadius: 2,
    top:70,
    left: 150,
    height: 25,
    backgroundColor:'white',
    width:'300'
})
currentWin.add(labelTitle1);

//
//I CUT OUT A LOT OF THE CODE HERE AS IT IS JUST THE SAME AS ABOVE...
//

// create a view to add the label and photo
    var photoContainerView = Ti.UI.createView({
        top: 310,
        left: 10,
        height: 230,
        width: Ti.UI.FILL
    });

    var photoLabel = Ti.UI.createLabel({
        text: 'Photo:',
        left: 0,
        height: Ti.UI.SIZE,
        width: Ti.UI.SIZE,
        font:{fontSize:18}      
    });

    photoContainerView.add(photoLabel);

    var photoView = Ti.UI.createImageView({
        image: imageUrl,
        top: 0,
        left: 125,
        height: 200,
        width: 200,
        borderColor: 'gray',
        borderWidth: 1
    });

    photoContainerView.add(photoView);
    currentWin.add(photoContainerView);


// create navigation buttons 
//
var button_previous = Titanium.UI.createButton({
    title: 'Previous',
    color: 'white',
    backgroundColor: '#464646',
    font:{fontSize:20,fontFamily:'Helvetica Neue'},
    bottom: 20,
    left:10,
    width: 100,
    height: 60
});

currentWin.add(button_previous);

var button_next = Titanium.UI.createButton({
    title: 'Next',
    color: 'white',
    backgroundColor: '#464646',
    font:{fontSize:20,fontFamily:'Helvetica Neue'},
    bottom: 20,
    right:10,
    width: 100,
    height: 60
});

currentWin.add(button_next);

我只想将事件侦听器添加到按钮中,这样我就可以返回/转发数据库中的记录,但是我不确定从哪里开始,以及需要使用什么代码。

任何建议都非常感谢。

JC

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-02 15:40:31

使用单击侦听器可以使用新数据刷新表,将当前位置存储在表中,并按如下方式对其进行页面浏览:

代码语言:javascript
复制
var currentPage = 0;
var pageSize = 25;
button_next.addEventListener('click', function(e) {
    currentPage++;
    // Load the data
    var sql = db.execute('SELECT * FROM photos where id>? LIMIT ?', currentPage * pageSize, pageSize);

    .... Your code to convert this statement to actual rows ....

    table.setData(yourUpdatedRowDataArray);
});

上一个按钮将以相同的方式工作,除非相反。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19739067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档