04-17-2012 03:00 PM
I want to create a toolbar like the one we see in twitter application.
I have created one like this. Have used custom manager, to distribute image evenly the whole length
Manager Class is as following
Manager customManager = new Manager(0)
{
protected void sublayout(int width, int height) {
setPositionChild(
getField(0),
0,
0);
layoutChild(
getField(0),
getField(0).getPreferredWidth(),
getField(0).getPreferredHeight());
setPositionChild(
getField(1),
Graphics.getScreenWidth()/2 - getField(1).getPreferredWidth()/2,
0);
layoutChild(
getField(1),
getField(1).getPreferredWidth(),
getField(1).getPreferredHeight());
setPositionChild(
getField(2),
Graphics.getScreenWidth() - getField(2).getPreferredWidth(),
0);
layoutChild(
getField(2),
getField(2).getPreferredWidth(),
getField(2).getPreferredHeight());
setExtent(width, 30);
}
};
I add images in the manager as following
DesignToolBar(customManager);
private void DesignToolBar(Manager hfm) {
Bitmap imgInbox = Bitmap.getBitmapResource("inbox-32.png");
fldInbox = new BitmapField(imgInbox){
protected boolean navigationClick(int status, int time) {
Dialog.alert("Inbox");
// KeypadListener.STATUS_FOUR_WAY or KeypadListener.STATUS_TRACKWHEEL
return true; //this says you handled the event
}
};
//fldInbox.setChangeListener(customListener);
Bitmap imgOutbox = Bitmap.getBitmapResource("outbox-32.png");
fldOutbox = new BitmapField(imgOutbox){
protected boolean navigationClick(int status, int time) {
Dialog.alert("Outbox");
// KeypadListener.STATUS_FOUR_WAY or KeypadListener.STATUS_TRACKWHEEL
return true; //this says you handled the event
}
};
//fldOutbox.setChangeListener(customListener);
Bitmap imgSearch = Bitmap.getBitmapResource("search-32.png");
search = new BitmapField(imgSearch){
protected boolean navigationClick(int status, int time) {
Dialog.alert("Search");
return true; //this says you handled the event
}
};
//search.setChangeListener(customListener);
hfm.add(fldInbox);
hfm.add(fldOutbox);
hfm.add(search);
hfm
.setBackground(BackgroundFactory.createLinearGradi entBackground(Color.WHITESMOKE,Color.WHITESMOKE,Co lor.DARKGRAY,Color.DARKGRAY));
}
The images display fine. But when I click them nothing happens. Am I missing something ?
04-18-2012 02:19 PM
Changed the code to following
fldInbox = new BitmapField(imgInbox, Field.FOCUSABLE|Field.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status, int time) {
Dialog.alert("Inbox");
// KeypadListener.STATUS_FOUR_WAY or KeypadListener.STATUS_TRACKWHEEL
return true; //this says you handled the event
}
};
Even then, Alert is not displaying !