Dear All, I have a problem when creating a UI on Blackberry.
First, i try to create a ChatLayoutManager class extended from Manager class. My layout has three component: topfield, mainfield and bottom field.
public class ChatLayoutManager extends Manager {
private Field bottomField;
private Field mainField;
private Field titleField;
public ChatLayoutManager(long style) {
super(style);
}
protected void sublayout(int width, int height) {
setExtent(width, height);
int y = 0;
if (bottomField != null) {
layoutChild(bottomField, width, height);
// This goes at the bottom of the screen
setPositionChild(bottomField, 0, height-bottomField.getHeight());
height -= bottomField.getHeight();
}
if (titleField != null) {
layoutChild(titleField, width, height);
// This goes at the top of the screen
setPositionChild(titleField, 0, 0);
height -= titleField.getHeight();
y += titleField.getHeight();
}
if (mainField != null) {
layoutChild(mainField, width, height);
// This goes just below the title field (if any)
setPositionChild(mainField, 0, y);
}
}
public void setMainField(Field f) {
mainField = f;
add(f);
}
public void setBottomField(Field f) {
bottomField = f;
add(f);
}
public void setTitleField(Field f) {
titleField = f;
add(f);
}
Then i create another field (ChatField) extended from manager to add to mainfield in the ChatLayoutManager class which i have created above.
public class ChatField extends Manager{
private Field _contentField[];
protected ChatField(){
super(Manager.HORIZONTAL_SCROLL | Manager.VERTICAL_SCROLL);
}
// TODO Auto-generated constructor stub}
protected synchronized void sublayout(int width, int height) {
// TODO Auto-generated method stub
setExtent(width, height);
int x = 0;
int y = 0;
if(_contentField.length > 0){
for(int i = 0 ;i<_contentField.length; i++){
//if(getManager() == this){
this.layoutChild(_contentField[i],
_contentField[i].getWidth(),
_contentField[i].getHeight());
this.setPositionChild(_contentField[i], x, y);
if(_contentField[i++]!= null){
if ((_contentField[i].getWidth() + _contentField[i].getWidth())
>= width){
x = 0;
y += _contentField[i].getHeight();
}
else{
x += _contentField[i].getWidth();
}
}
//}
}
}
}
public void setContentField(Field field[]){
_contentField = field;
}
}
And now, when i create some fields(such as TextField, BitmapField ...) added to ChatField, the program has an error "Field is not a child of this manager". The reason is when the framework invokes the sublayout function of the ChatField class , when sublayout starts calling layoutChild function the manager of field is not ChatField but ChatlayoutManager.
I've experience hard time trying to resolve this problem, still I have no solution. Anybody can give me some suggestions? I really appreciate.