Blackberry中自定义ListView的字段更改侦听器?
我在一个应用程序中工作,我必须在列表视图中显示联系人。我在垂直字段管理器和标签字段的帮助下创建了列表视图 我有一个Email字段和Phone number字段,我必须在上面呼叫一个点击式侦听器 我已经在我的类上实现了侦听器,但由于单击事件而失败。不显示任何单击事件 目前,我正在使用以下代码:Blackberry中自定义ListView的字段更改侦听器?,listview,blackberry,Listview,Blackberry,我在一个应用程序中工作,我必须在列表视图中显示联系人。我在垂直字段管理器和标签字段的帮助下创建了列表视图 我有一个Email字段和Phone number字段,我必须在上面呼叫一个点击式侦听器 我已经在我的类上实现了侦听器,但由于单击事件而失败。不显示任何单击事件 目前,我正在使用以下代码: public class CustomListView extends VerticalFieldManager implements FieldChangeListener{ private Ve
public class CustomListView extends VerticalFieldManager implements FieldChangeListener{
private VerticalFieldManager mVFM=null;
private Font _allFonts=null;
private Font _headingFonts=null;
/**
* @param resultVec
*/
public CustomListView() {
super(VerticalFieldManager.VERTICAL_SCROLL);
setMargin(0, 0, 10, 0);
int resolutionWidth = Display.getWidth(); // PLANNING FOR THREE FIXED RESOLUTIONS 320, 360 AND 480
//HANDLE WITH THE CODE DIFFERENT DEVICES
if(resolutionWidth>=480){
_allFonts = ApplicationFont.explainationFont_18;
_headingFonts = ApplicationFont.labelFont_18;
}else if(resolutionWidth >=360){
_allFonts = ApplicationFont.explainationFont_18;
_headingFonts = ApplicationFont.labelFont_18;
}else{//RESOLUTION WIDTH <=320
_allFonts = ApplicationFont.explainationFont_15;
_headingFonts = ApplicationFont.labelFont_15;
}
int maxLength = Constants.Country_List.length;
int minLength = 0;
if(maxLength >= 0){
for (int i = minLength; i < maxLength; i++) {
VerticalFieldManager vfm = getVerticalFieldManager();
vfm.setMargin(0, 10, 0, 10);
LabelField countryLabel = new LabelField();
countryLabel.setText(Constants.Country_List[i]);
//countryLabel.setFont(_allFonts);
countryLabel.setMargin(10, 0, 10, 0);
HorizontalFieldManager countryHFM = new HorizontalFieldManager(Manager.USE_ALL_WIDTH);
countryHFM.add(countryLabel);
countryHFM.setBackground(BackgroundFactory
.createSolidBackground(Constants.LightGreyBgColorCode));
LabelField addressLabel = new LabelField();
addressLabel.setText(Constants.Address_List[i]);
//addressLabel.setFont(_allFonts);
LabelField stateLabel = new LabelField();
stateLabel.setText(Constants.State_List[i]);
// stateLabel.setFont(_allFonts);
LabelField cityLabel = new LabelField(){
protected void paint(Graphics graphics) {
graphics.setColor(Constants.DarkGreyTextColorCode);
super.paint(graphics);
}
};
cityLabel.setText(Constants.City_List[i]);
//cityLabel.setFont(_allFonts);
LabelField phoneLabel = new LabelField(){
protected void paint(Graphics graphics) {
graphics.setColor(Constants.DarkGreyTextColorCode);
super.paint(graphics);
}
};
phoneLabel.setText("Phone(s):");
//phoneLabel.setFont(_allFonts);
LabelField numLabel = new LabelField(){
protected void paint(Graphics graphics) {
graphics.setColor(Constants.blueTextColor);
super.paint(graphics);
}
};
numLabel.setText(Constants.Phone_List[i]);
//numLabel.setFont(_allFonts);
HorizontalFieldManager phoneNumberHFM = new HorizontalFieldManager();
phoneNumberHFM.add(phoneLabel);
phoneNumberHFM.add(numLabel);
LabelField emailLabel = new LabelField(){
protected void paint(Graphics graphics) {
graphics.setColor(Constants.DarkGreyTextColorCode);
super.paint(graphics);
}
};
emailLabel.setText("Email:");
//emailLabel.setFont(_allFonts);
LabelField emailIdLabel = new LabelField(){
protected void paint(Graphics graphics) {
graphics.setColor(Constants.blueTextColor);
super.paint(graphics);
}
};
emailIdLabel.setText(Constants.Email_List[i]);
//emailIdLabel.setFont(_allFonts);
HorizontalFieldManager emailIdHFM = new HorizontalFieldManager();
emailIdHFM.add(emailLabel);
emailIdHFM.add(emailIdLabel);
mVFM = new VerticalFieldManager(USE_ALL_WIDTH /*|FOCUSABLE*/);
mVFM.setMargin(20, 0, 20, 0);
mVFM.add(countryHFM);
mVFM.add(addressLabel);
mVFM.add(stateLabel);
mVFM.add(cityLabel);
mVFM.add(phoneNumberHFM);
mVFM.add(emailIdHFM);
mVFM.add(new NullField(FOCUSABLE));
vfm.add(mVFM);
/*SeparatorField separater = new SeparatorField(Constants.LightGreyBgColorCode);
separater.setMargin(0, 10, 0, 10);*/
vfm.add(new SeparatorField(Constants.LightGreyBgColorCode));
add(vfm);
}
}
}
private VerticalFieldManager getVerticalFieldManager() {
VerticalFieldManager verticalFieldManager = new VerticalFieldManager(
VerticalFieldManager.FOCUSABLE
| VerticalFieldManager.FIELD_HCENTER
| VerticalFieldManager.VERTICAL_SCROLL
| VerticalFieldManager.USE_ALL_WIDTH) {
protected boolean touchEvent(TouchEvent message) {
if (message.getEvent() == TouchEvent.CLICK) {
navigationClick(0, 0);
}
return super.touchEvent(message);
}
public boolean navigationClick(int status, int time) {
fieldChangeNotify(1);
return true;
}
protected void onFocus(int direction) {
super.onFocus(direction);
setBackground(BackgroundFactory
.createSolidBackground(/*0x186DEF*/Constants.WhiteBgColorCode));
invalidate();
}
protected void onUnfocus() {
super.onUnfocus();
setBackground(BackgroundFactory
.createSolidBackground(Constants.WhiteBgColorCode));
invalidate();
}
};
return verticalFieldManager;
}
public void fieldChanged(Field field, int context) {
}
}
公共类CustomListView扩展VerticalFieldManager实现FieldChangeListener{
私有VerticalFieldManager mVFM=null;
私有字体_allFonts=null;
私有字体_headingFonts=null;
/**
*@param resultVec
*/
公共CustomListView(){
超级(垂直字段管理器。垂直滚动);
setMargin(0,0,10,0);
int resolutionWidth=Display.getWidth();//规划三种固定分辨率320、360和480
//使用不同的设备处理代码
如果(分辨率宽度>=480){
_allFonts=ApplicationFont.explainationFont_18;
_headingFonts=ApplicationFont.labelFont_18;
}否则如果(分辨率宽度>=360){
_allFonts=ApplicationFont.explainationFont_18;
_headingFonts=ApplicationFont.labelFont_18;
}else{//分辨率宽度=0){
对于(int i=minLength;ipublic MyScreen() {
// Set the displayed title of the screen
setTitle("Test ZoomScreen");
ButtonField zoomButton = new ButtonField("Zoom Screen Test");
FieldChangeListener listener=new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
EncodedImage ei = EncodedImage.getEncodedImageResource("Koala.jpg");
UiApplication.getUiApplication().pushScreen(new ZoomScreen(ei));
}
};
zoomButton.setChangeListener(listener);
add(zoomButton);
}