Skip to content

Instantly share code, notes, and snippets.

@Amimul100
Created August 23, 2014 10:17
Show Gist options
  • Save Amimul100/4d9754b65f25d7435eaf to your computer and use it in GitHub Desktop.
Save Amimul100/4d9754b65f25d7435eaf to your computer and use it in GitHub Desktop.
Android Equivalent to iOS indexed UITableView
/*
Hello, Here is a workaround which can be Android equivalent to iOS indexed UITableView.First, Make a view and add it to left or right on the page where you want to put it on the window. add another 26 view in it for A-Z.
On the click of alphabet's view you can scroll the table by scrollToIndex( ).
*/
{code}
Titanium.UI.setBackgroundColor('#000');
var tabGroup = Titanium.UI.createTabGroup();
var win1 = Titanium.UI.createWindow({
title : 'Tab 1',
backgroundColor : '#fff'
});
var tab1 = Titanium.UI.createTab({
icon : 'KS_nav_views.png',
title : 'Tab 1',
window : win1
});
var tblSearchIndex = Ti.UI.createTableView();
var tblData = [];
var indexData = [];
var indexContainer = Ti.UI.createView({
height : Ti.Platform.displayCaps.platformHeight,
width : 12,
top : 0,
right : 0
});
for( i = 65, charTop = 0; i <= 90; i++, charTop += 15) {
var tblRow = Ti.UI.createTableViewRow({
backgroundColor : 'gray'
});
tblRow.title = String.fromCharCode(i) + " " + (i-65).toString();
indexData.push({
title : String.fromCharCode(i),
index : i
});
tblData.push(tblRow);
var charView = Ti.UI.createLabel({
top : charTop,
height : 15,
width : 12,
font : {
fontSize : 12
},
textAlign : 'center',
text : String.fromCharCode(i),
// backgroundColor : "transparent"
backgroundColor : "red",
color : 'black'
});
charView.addEventListener('click', function(e) {
tblSearchIndex.scrollToIndex(e.source.text.charCodeAt(0)-65);
alert(e.source.text.charCodeAt(0)-65);
});
indexContainer.add(charView);
}
tblSearchIndex.data = tblData;
tblSearchIndex.index = indexData;
tblSearchIndex.addEventListener('click', function(e){
alert(e.index);
});
win1.add(tblSearchIndex);
win1.add(indexContainer);
tabGroup.addTab(tab1);
tabGroup.open();
{code}
/*
Hope it helps.
*/
@muj2022
Copy link

muj2022 commented Aug 23, 2014

Free

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment