2010-03-16 60 views
0

在我的屏幕上我有ButtonField和CustomButtonField。 这两个都已添加到我的屏幕Listner。如何确定黑莓应用程序中的对象类型?

myScreen.add(new ButtonField(“click me”)); myScreen.add(new CustomButtonField(“Click me Again”));

现在我想知道哪个按钮被点击和fieldChanged函数中的对象类型。

公共无效fieldChanged(场场,INT上下文){

//这里 - 如何确定//哪个对象被点击 // ButtonField字段或CustomButtonField对象 的类型???? }

好心帮 感谢 SIA

回答

0
instanceof is your friend: 

public void fieldChange(Field field, int context) { 
    if(field instanceof CustomButtonField) 
     ;//do something 
    else if(field instanceof ButtonField) 
     ;//do something 
}