シンプルな「進む」ボタンと「戻る」ボタンを使用して、sqlite データベース内のレコード間を移動する方法を見つけようとしています。
データベースにアクセスしてレコードを表示できます。これを行うには、レコードのテーブルビューを作成します。レコードをクリックすると、詳細が表示されます。次に、このページのボタンでデータベースをナビゲートするだけです。
ボタンにどのコードを適用する必要があるのか わかりません。
これはウィンドウのコードです。
// 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