问题
I am developing one app in which i need to call at particular phone number
for that i have take LableField
and make Number.setChangeListener(this);
and implement its method fieldChanged
and try to handle event but i cant able to do it with this lablefield
Here is code ::
import net.rim.blackberry.api.invoke.Invoke;
import net.rim.blackberry.api.invoke.PhoneArguments;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.NullField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.BackgroundFactory;
public class AboutM1 extends MainScreen implements FieldChangeListener {
VerticalFieldManager TOPVFM , DescriptionVFM,BottomVFM;
HorizontalFieldManager TOPHFM,CallHFM,EmailHFM,VIsitUsHFM ;
LabelField toplable,Description,Description2,Number,callus,Email,EmailID,Visitus,VisitLink;
Bitmap logom1;
BitmapField imgField;
public AboutM1() {
((VerticalFieldManager) getMainManager())
.setBackground(BackgroundFactory
.createSolidBackground(0xEDEDED));
TOPVFM = new VerticalFieldManager(USE_ALL_WIDTH);
TOPHFM = new HorizontalFieldManager(
FIELD_HCENTER | FIELD_VCENTER);
AllBITMAPDeclaration();
toplable = new LabelField("\n Welcome to", FIELD_BOTTOM) {
public void paint(Graphics g) {
g.setBackgroundColor(0xECECEC);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.RED);
g.clear();
super.paint(g);
}
};
FontFamily fontFamily[] = FontFamily.getFontFamilies();
Font font = fontFamily[1].getFont(FontFamily.CBTF_FONT, 20);
font = fontFamily[1].getFont(Font.BOLD, 25);
toplable.setFont(font);
imgField = new BitmapField(logom1, FIELD_BOTTOM);
TOPHFM.add(toplable);
TOPHFM.add(imgField);
TOPVFM.add(TOPHFM);
add(TOPVFM);
LabelField Greenline = new LabelField(
"_______________________________________") {
protected void paint(Graphics g) {
g.setColor(0x324F85);
super.paint(g);
}
};
add(Greenline);
DescriptionVFM = new VerticalFieldManager(
VERTICAL_SCROLL);
Description = new LabelField(
"\nasdasdasd as da sd asd a sd reert er ter t e",
USE_ALL_WIDTH);
Description2 = new LabelField(
"\n\n About Us \n For customer care \n\n");
/*
* add(Description); add(Description2);
*/
DescriptionVFM.add(Description);
DescriptionVFM.add(new NullField(NullField.FOCUSABLE));
DescriptionVFM.add(Description2);
/******************************Bottom Area******************************************/
BottomVFM = new VerticalFieldManager(USE_ALL_WIDTH );
CallHFM = new HorizontalFieldManager(
FIELD_VCENTER);
callus = new LabelField("Call: ", FIELD_VCENTER);
Number = new LabelField("+91-79-30487400", FIELD_VCENTER) {
protected void paint(Graphics g) {
g.setColor(0x324F85);
// g.fillRoundRect(0, 0, 50, 5, 7, 7);
super.paint(g);
}
};
font = fontFamily[2].getFont(Font.BOLD, 18);
Number.setFont(font);
CallHFM.add(callus);
CallHFM.add(Number);
Number.setChangeListener(this);
EmailHFM = new HorizontalFieldManager(FIELD_VCENTER);
Email = new LabelField("Email: ", FIELD_VCENTER);
EmailID = new LabelField("Customasdercare@m1asdshopping.com", FIELD_VCENTER) {
protected void paint(Graphics g) {
g.setColor(0x324F85);
super.paint(g);
}
};
EmailID.setFont(font);
EmailID.setChangeListener(this);
EmailHFM.add(Email);
EmailHFM.add(EmailID);
VIsitUsHFM = new HorizontalFieldManager(FIELD_VCENTER);
Visitus = new LabelField("Visit us at: ", FIELD_VCENTER);
VisitLink = new LabelField("www.asdasd.com", FIELD_VCENTER) {
protected void paint(Graphics g) {
g.setColor(0x324F85);
super.paint(g);
}
};
VisitLink.setFont(font);
VisitLink.setChangeListener(this);
VIsitUsHFM.add(Visitus);
VIsitUsHFM.add(VisitLink);
BottomVFM.add(CallHFM);
BottomVFM.add(EmailHFM);
BottomVFM.add(VIsitUsHFM);
// add(BottomVFM);
DescriptionVFM.add(BottomVFM);
/********************************* END BOTTOM ************************************************/
add(DescriptionVFM);
}
private void AllBITMAPDeclaration() {
// TODO Auto-generated method stub
logom1 = Bitmap.getBitmapResource("logo36X36.png");
}
public void fieldChanged(Field field, int context) {
// TODO Auto-generated method stub
if(field == Number )
{
Dialog.alert("asdasd");
/* PhoneArguments arguments = new PhoneArguments(PhoneArguments.ARG_CALL, "180065449877");
Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, arguments);*/
}
if(field == EmailID)
{
Dialog.alert("asdasd");
}
if(field == VisitLink)
{
Dialog.alert("asdasd");
}
}
}
回答1:
try this -
LabelField Number = new LabelField("+91-79-30345487400a5675675676", FIELD_VCENTER|Field.FOCUSABLE) {
protected void paint(Graphics g) {
g.setColor(0x324F85);
// g.fillRoundRect(0, 0, 50, 5, 7, 7);
super.paint(g);
}
protected boolean navigationClick(int status, int time) {
Dialog.alert("clicked");
return super.navigationClick(status, time);
}
};
add(Number);
回答2:
You need to implement the method navigationClick
on your LabelField
.
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
来源:https://stackoverflow.com/questions/11755087/issue-with-onclicklistner-with-lablefield-blackberry