Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Hello Everyone,
I am working on a Screen , the height of Screen reduced after click on CheckBox (when change listener call).
Here is the code :-
public class IA_SearchScreen extends MainScreen implements FieldChangeListener
{
private CheckboxField ch1;
private CheckboxField ch2;
private CheckboxField ch3;
private CheckboxField r1;
private CheckboxField r2;
private CheckboxField r3;
private boolean togle_r1 = true;
private boolean togle_r2;
private boolean togle_r3;
private AutoTextEditField iaDescriptionEditField;
private AutoTextEditField streetEditField;
private AutoTextEditField postCodeEditField ;
private AutoTextEditField radiusEditField ;
private Bitmap filterButton_F = Bitmap.getBitmapResource("filter_ focus.png");
private Bitmap filterButton_N = Bitmap.getBitmapResource("filter_Unfocuss.png");
private int temp_mgr_Height = 0;
private StatusManager status_Manager;
private ImageButton map_Button;
private ImageButton favorite_Button;
private ImageButton search_Button;
private Calendar calendar;
private LabelField _startDateLabelField;
private LabelField _startTimeLabelField;
private LabelField _endDateLabelField;
private LabelField _endTimeLabelField;
private String[] street_Array;
private String[] postCode_Array;
private String SearchString = Global.EMPTY;
private String DisruptionsType = Global.EMPTY;
private String Lat = Global.EMPTY;
private String Long = Global.EMPTY;
private String Radius = Global.EMPTY;
private String Severity = Global.EMPTY;
private String StartDate = Global.EMPTY;
private String EndDate = Global.EMPTY;
private String PostCode = Global.EMPTY;
private String StreetName = Global.EMPTY;
private String AllDates = Global.EMPTY;
private VerticalFieldManager _workSpace ;
public IA_SearchScreen()
{
super(Screen.USE_ALL_HEIGHT);
_workSpace = (VerticalFieldManager)getMainManager();
/**
* Initialize Screen Components
* */
iaDescriptionEditField = new AutoTextEditField("" , "", 500, EditField.NO_NEWLINE | EditField.NON_SPELLCHECKABLE)
{
protected void layout(int width, int height)
{
super.layout(width, height);
setExtent((Global.Display_Width - 40), getHeight());
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
super.paint(graphics);
}
};
iaDescriptionEditField.setFont(Global.arialFont_Plain_16);
SizedHFM _source0 = new SizedHFM(Global.Display_Width -30);
_source0.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x867E42, Border.STYLE_FILLED), true);
_source0.add(iaDescriptionEditField);
HorizontalFieldManager hfm_0 = new HorizontalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.setExtent(maxWidth, maxHeight);
Field f = getField(0);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
setPositionChild(f, 10, 25);
temp_mgr_Height = getPreferredHeightOfChild(f) +20;
f = getField(1);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
//setPositionChild(f, Global.Display_Width -70, 25);
setPositionChild(f, Global.Display_Width -55, 25);
setExtent(maxWidth,temp_mgr_Height + 35);
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.setFont(Global.arialFont_Bold_16);
graphics.drawText("Search by Incident or Accident Description", 15, 5);
graphics.drawRect(5, 1, getWidth()-10, getHeight()-2);
super.paint(graphics);
}
};
hfm_0.add(_source0);
hfm_0.add(new LabelField());
/**
* StreetEditField Manager START
* */
streetEditField = new AutoTextEditField("" , "", 500, EditField.NO_NEWLINE | EditField.NON_SPELLCHECKABLE)
{
protected void layout(int width, int height)
{
super.layout(width, height);
setExtent((Global.Display_Width - 40), getHeight());
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
super.paint(graphics);
}
};
streetEditField.setFont(Global.arialFont_Plain_16);
SizedHFM _source = new SizedHFM(Global.Display_Width - 65);
_source.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x867E42, Border.STYLE_FILLED), true);
_source.add(streetEditField);
ImageButton btn_go_streetEditField = new ImageButton(filterButton_N , filterButton_F)
{
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(1);
return true;
}
};
btn_go_streetEditField.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
street_Invoke();
}
});
HorizontalFieldManager hfm_1 = new HorizontalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.setExtent(maxWidth, maxHeight);
Field f = getField(0);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
setPositionChild(f, 10, 25);
temp_mgr_Height = getPreferredHeightOfChild(f) +20;
f = getField(1);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
//setPositionChild(f, Global.Display_Width -70, 25);
setPositionChild(f, Global.Display_Width -filterButton_N.getWidth()-10, 25);
setExtent(maxWidth,temp_mgr_Height + 35);
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.setFont(Global.arialFont_Plain_16);
graphics.drawText("Street", 15, 5);
graphics.drawRect(5, 1, getWidth()-10, getHeight()-2);
super.paint(graphics);
}
};
hfm_1.add(_source);
hfm_1.add(btn_go_streetEditField);
/**
* StreetEditField Manager END
* */
/**
* PostCodeEditField Manager START
* */
postCodeEditField = new AutoTextEditField("" , "", 500, EditField.NO_NEWLINE | EditField.NON_SPELLCHECKABLE)
{
protected void layout(int width, int height)
{
super.layout(width, height);
setExtent((Global.Display_Width - 40), getHeight());
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
super.paint(graphics);
}
};
postCodeEditField.setFont(Global.arialFont_Plain_16);
SizedHFM _source1 = new SizedHFM(Global.Display_Width -65);
_source1.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x867E42, Border.STYLE_FILLED), true);
_source1.add(postCodeEditField);
ImageButton btn_go_postCodeEditField = new ImageButton(filterButton_N , filterButton_F)
{
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(1);
return true;
}
};
btn_go_postCodeEditField.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
postCode_Invoke();
}
});
HorizontalFieldManager hfm_2 = new HorizontalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.setExtent(maxWidth, maxHeight);
Field f = getField(0);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
setPositionChild(f, 10, 25);
temp_mgr_Height = getPreferredHeightOfChild(f) +20;
f = getField(1);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
//setPositionChild(f, Global.Display_Width -70, 25);
setPositionChild(f, Global.Display_Width - filterButton_N.getWidth()-10, 25);
setExtent(maxWidth,temp_mgr_Height + 35);
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.setFont(Global.arialFont_Plain_16);
graphics.drawText("Post code", 15, 5);
graphics.drawRect(5, 1, getWidth()-10, getHeight()-2);
super.paint(graphics);
}
};
hfm_2.add(_source1);
hfm_2.add(btn_go_postCodeEditField);
/**
* PostCodeEditField Manager END
* */
radiusEditField = new AutoTextEditField("" , "", 5, EditField.NO_NEWLINE |AutoTextEditField.FILTER_INTEGER )
{
protected void layout(int width, int height)
{
super.layout(width, height);
setExtent((Global.Display_Width - 40), getHeight());
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
super.paint(graphics);
}
};
radiusEditField.setFont(Global.arialFont_Plain_16);
SizedHFM _source3 = new SizedHFM(Global.Display_Width -30);
_source3.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x867E42, Border.STYLE_FILLED), true);
_source3.add(radiusEditField);
HorizontalFieldManager hfm_3 = new HorizontalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.setExtent(maxWidth, maxHeight);
Field f = getField(0);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
setPositionChild(f, 10, 25);
temp_mgr_Height = getPreferredHeightOfChild(f) +20;
f = getField(1);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
//setPositionChild(f, Global.Display_Width -70, 25);
setPositionChild(f, Global.Display_Width -55, 25);
setExtent(maxWidth,temp_mgr_Height + 35);
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.setFont(Global.arialFont_Bold_16);
graphics.drawText("Radius (in Meters)", 15, 5);
graphics.drawRect(5, 1, getWidth()-10, getHeight()-2);
super.paint(graphics);
}
};
hfm_3.add(_source3);
hfm_3.add(new LabelField());
/**
* Start Date & Time
* */
_startDateLabelField = new LabelField("")
{
protected void layout(int width, int height) {
super.layout(150, 25);
super.setExtent(150, 25);
}
public boolean isFocusable() {
return true;
}
};
_startTimeLabelField = new LabelField("")
{
protected void layout(int width, int height) {
super.layout(150, 25);
super.setExtent(150, 25);
}
public boolean isFocusable() {
// TODO Auto-generated method stub
return true;
}
};
HorizontalFieldManager startDateNTimeManager = new HorizontalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.setExtent(Global.Display_Width,/*temp_mgr_Height + 25*/ 70);
Field f = getField(0);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
setPositionChild(f, 20, 30);
temp_mgr_Height = getPreferredHeightOfChild(f) +20;
f = getField(1);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
//setPositionChild(f, Global.Display_Width -70, 25);
setPositionChild(f, Global.Display_Width -120, 30);
setExtent(maxWidth,/*temp_mgr_Height + 25*/ 70);
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.setFont(Global.arialFont_Bold_16);
graphics.drawText("Start Date & Time", 10, 5);
graphics.drawRect(9, 25, 141, 30);
graphics.drawRect((Global.Display_Width - 151), 25, 141, 30);
graphics.drawRect(5, 1, getWidth()-10, getHeight()-2);
super.paint(graphics);
}
};
startDateNTimeManager.add(_startDateLabelField);
startDateNTimeManager.add(_startTimeLabelField);
/**
* End Date & Time
* */
_endDateLabelField = new LabelField("")
{
protected void layout(int width, int height) {
super.layout(150, 25);
super.setExtent(150, 25);
}
public boolean isFocusable() {
return true;
}
};
_endTimeLabelField = new LabelField("")
{
protected void layout(int width, int height) {
super.layout(150, 25);
super.setExtent(150, 25);
}
public boolean isFocusable() {
// TODO Auto-generated method stub
return true;
}
};
_startDateLabelField.setFont(Global.arialFont_Plain_18);
_startTimeLabelField.setFont(Global.arialFont_Plain_18);
_endDateLabelField.setFont(Global.arialFont_Plain_18);
_endTimeLabelField.setFont(Global.arialFont_Plain_18);
HorizontalFieldManager endDateNTimeManager = new HorizontalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.setExtent(Global.Display_Width,/*temp_mgr_Height + 25*/ 70);
Field f = getField(0);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
setPositionChild(f, 20, 30);
temp_mgr_Height = getPreferredHeightOfChild(f) +20;
f = getField(1);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
//setPositionChild(f, Global.Display_Width -70, 25);
setPositionChild(f, Global.Display_Width -120, 30);
setExtent(Global.Display_Width,/*temp_mgr_Height + 25*/ 70);
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.setFont(Global.arialFont_Bold_16);
graphics.drawText("End Date & Time", 10, 5);
graphics.drawRect(9, 25, 141, 30);
graphics.drawRect((Global.Display_Width - 151), 25, 141, 30);
graphics.drawRect(5, 1, getWidth()-10, getHeight()-2);
super.paint(graphics);
}
};
endDateNTimeManager.add(_endDateLabelField);
endDateNTimeManager.add(_endTimeLabelField);
/**
* Add Components to Screen
* */
LabelField searchByLocation = new LabelField("Search by Location")
{
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
super.paint(graphics);
}
};
searchByLocation.setFont(Global.arialFont_Bold_18);
insertSearchModeManager();
_workSpace.add(hfm_0);
searchByLocation.setMargin(5, 5, 5, 10);
_workSpace.add(searchByLocation);
_workSpace.add(hfm_1);
_workSpace.add(hfm_2);
_workSpace.add(hfm_3);
LabelField selectStartDateHeader = new LabelField("Select start date & end dates to check incidents in the future");
selectStartDateHeader.setFont(Global.arialFont_Bold_16);
selectStartDateHeader.setMargin(5, 5, 5, 10);
_workSpace.add(selectStartDateHeader);
insertDateSelectionManager();
startDateNTimeManager.setMargin(10, 0, 10, 0);
_workSpace.add(startDateNTimeManager);
_workSpace.add(endDateNTimeManager);
ButtonField btn_go = new ButtonField("Go" ,FIELD_HCENTER)
{
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(1);
return true;
}
};
btn_go.setMargin(10, 0, 0, 10);
_workSpace.add(btn_go);
// add(_workSpace);
btn_go.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
invokeAISearch();
}
});
/**
* Status Manager
* */
insertStatusManager();
/**
* Very First time r1 = All days should be selected
* */
/*r1.setSelected(true);
invokeDays_Calculatio();*/
}
protected void invokeAISearch()
{ }
private String getAllDates()
{
String dateString = Global.EMPTY;
return dateString;
}
private String getStartDateTime()
{
String startDateString = Global.EMPTY;
return startDateString;
}
private String getEndDateTime() {
String endDateString = Global.EMPTY;
return endDateString;
}
private String getSeverity() {
String sevString = Global.EMPTY;
return sevString;
}
private void show_AI(final Vector v_temp)
{
}
private void insertSearchModeManager() {
ch1 = new CheckboxField("Severe", true)
{
protected void layout(int width, int height) {
super.layout(getPreferredWidth(), height);
super.setExtent(getPreferredWidth(), height);
}
};
ch2 = new CheckboxField("Moderate", true)
{
protected void layout(int width, int height) {
super.layout(getPreferredWidth(), height);
super.setExtent(getPreferredWidth(), height);
}
};
ch3 = new CheckboxField("Slight", true)
{
protected void layout(int width, int height) {
super.layout(getPreferredWidth(), height);
super.setExtent(getPreferredWidth(), height);
}
};
ch1.setFont(Global.arialFont_Plain_16);
ch2.setFont(Global.arialFont_Plain_16);
ch3.setFont(Global.arialFont_Plain_16);
HorizontalFieldManager dateSelectionManager = new HorizontalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(maxWidth, maxHeight);
setExtent(360, 50);
}
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.drawRect(5, 0, getWidth()-10, getHeight());
super.paint(graphics);
}
};
ch1.setMargin(0, 0, 0, 10);
ch2.setMargin(0, 0, 0, 20);
ch3.setMargin(0, 0, 0, 20);
dateSelectionManager.add(ch1);
dateSelectionManager.add(ch2);
dateSelectionManager.add(ch3);
LabelField selectStartDateHeader = new LabelField("Search by Severity");
selectStartDateHeader.setFont(Global.arialFont_Bold_16);
selectStartDateHeader.setMargin(5, 5, 5, 10);
_workSpace.add(selectStartDateHeader);
_workSpace.add(dateSelectionManager);
}
private void insertDateSelectionManager()
{
r1 = new CheckboxField( "All Dates" , true)
{
protected void layout(int width, int height) {
super.layout(getPreferredWidth(), height);
}
};
r2 = new CheckboxField("Tomorrow",false)
{
protected void layout(int width, int height) {
super.layout(getPreferredWidth(), height);
}
};
r3 = new CheckboxField("Next 7 days",false)
{
protected void layout(int width, int height) {
super.layout(getPreferredWidth(), height);
}
};
HorizontalFieldManager dateSelectionManager = new HorizontalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(Global.Display_Width, 50);
setExtent(Global.Display_Width, 50);
}
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.drawRect(5, 0, getWidth()-10, getHeight());
super.paint(graphics);
}
};
r1.setFont(Global.arialFont_Plain_16);
r2.setFont(Global.arialFont_Plain_16);
r3.setFont(Global.arialFont_Plain_16);
r1.setMargin(0, 0, 0, 20);
r2.setMargin(0, 0, 0, 20);
r3.setMargin(0, 0, 0, 20);
dateSelectionManager.add(r1);
dateSelectionManager.add(r2);
dateSelectionManager.add(r3);
add(dateSelectionManager);
r1.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
if ( nonProgrammaticChange(context) )
{
invokeDays_Calculation(r1);
}
}
});
r2.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
if ( nonProgrammaticChange(context) )
{
invokeDays_Calculation(r2);
}
}
});
r3.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
if ( nonProgrammaticChange(context) )
{
invokeDays_Calculation(r3);
}
}
});
}
private boolean nonProgrammaticChange (int context) {
return (context & FieldChangeListener.PROGRAMMATIC) != FieldChangeListener.PROGRAMMATIC;
}
protected void invokeDays_Calculation(CheckboxField selectedField)
{
r1.setChecked(false);
r2.setChecked(false);
r3.setChecked(false);
if(selectedField.equals(r1))
{
togle_r1 = !togle_r1;
if(togle_r1)
{
r1.setChecked(true);
togle_r2 = false;
togle_r3 = false;
_startDateLabelField.setText("");
_startTimeLabelField.setText("");
_endDateLabelField.setText("");
_endTimeLabelField.setText("");
}
else
{
if(!togle_r1 && !togle_r2 && !togle_r3)
{
Calendar todaysDate = Calendar.getInstance();
int tDayStr = todaysDate.get(Calendar.DATE);
int tMonStr = todaysDate.get(Calendar.MONTH);
int tYearStr = todaysDate.get(Calendar.YEAR);
/**
* In Calendar class Month start form 0 thats why I incremented one time
* */
++tMonStr;
/*System.out.println("t Date "+tDayStr);
System.out.println("t Month "+tMonStr);
System.out.println("t Year "+tYearStr);*/
String startDateStr = tDayStr+"/"+tMonStr+"/"+tYearStr;
_startDateLabelField.setText(startDateStr);
_startTimeLabelField.setText("00:00");
_endDateLabelField.setText(startDateStr);
_endTimeLabelField.setText("23:59");
}
}
}
if(selectedField.equals(r2))
{
togle_r2 = !togle_r2;
if(togle_r2)
{
r2.setChecked(true);
togle_r1 = false;
togle_r3 = false;
Calendar todaysDate = Calendar.getInstance();
int tDayStr = todaysDate.get(Calendar.DATE);
int tMonStr = todaysDate.get(Calendar.MONTH);
int tYearStr = todaysDate.get(Calendar.YEAR);
++tDayStr;
/**
* In Calendar class Month start form 0 thats why I incremented one time
* */
++tMonStr;
/*System.out.println("t Date "+tDayStr);
System.out.println("t Month "+tMonStr);
System.out.println("t Year "+tYearStr);*/
String startDateStr = tDayStr+"/"+tMonStr+"/"+tYearStr;
_startDateLabelField.setText(startDateStr);
_startTimeLabelField.setText("00:00");
_endDateLabelField.setText(startDateStr);
_endTimeLabelField.setText("23:59");
}
}
if(selectedField.equals(r3))
{
togle_r3 = !togle_r3;
if(togle_r3)
{
r3.setChecked(true);
togle_r1 = false;
togle_r2 = false;
Calendar todaysDate = Calendar.getInstance();
int tDayStr = todaysDate.get(Calendar.DATE);
int tMonStr = todaysDate.get(Calendar.MONTH);
int tYearStr = todaysDate.get(Calendar.YEAR);
/**
* In Calendar class Month start form 0 thats why I incremented one time
* */
++tMonStr;
/*System.out.println("t Date "+tDayStr);
System.out.println("t Month "+tMonStr);
System.out.println("t Year "+tYearStr);*/
String startDateStr = tDayStr+"/"+tMonStr+"/"+tYearStr;
_startDateLabelField.setText(startDateStr);
_startTimeLabelField.setText("00:00");
tDayStr += 7;
startDateStr = tDayStr+"/"+tMonStr+"/"+tYearStr;
_endDateLabelField.setText(startDateStr);
_endTimeLabelField.setText("23:59");
}
}
}
public void fieldChanged(Field field, int context) {
// TODO Auto-generated method stub
}
protected void street_Invoke()
{
}
protected void postCode_Invoke() {
}
void showStreetPopUp(final String[] street_Array)
{
}
public void showCarParkingStreetPopUp(final String[] postCode_Array)
{
}
public void updateStreetField(String strVal)
{
}
public void updatePostField(String strVal) {
}
public boolean onClose()
{
setDirty(false);
return super.onClose();
}
protected void sublayout(int width, int height)
{
super.sublayout(Global.Display_Width, Global.Display_Height + 100);
super.setExtent(Global.Display_Width, Global.Display_Height + 100);
}
protected void paint(Graphics graphics)
{
// TODO Auto-generated method stub
super.paint(graphics);
}
}
Note : the code is working fine in 5.0 OS but in 6.0 & 7.0 it creates problem.
Please let me know why I am getting the issue .
The problem is that you have made the app specific for a particular device on OS 5.0 which was obviously non-touch. Now on Touch devices, the sizes of buttons and checkboxes are much larger whereas you are trying to constrain them to smaller sizes. So the checkboxes will normally take whatever setextent you have done, but when focussed, they will try to make space for themselves which would disturb your screen layout. Remove the artificial constraining in the checkboxes and your immediate problem may get solved.
However, There are a LOT of issues in this code that may give rise to problems later.
Use of Screen.USE_ALL_HEIGHT will not make the take up the entire display.
You are unnecessarily overriding each and every field to somehow constrain their height. And you are doing it wrong. For example, in iaDescriptionEditField you have given full width for layout but then constrained its size. This will result in a the field not getting painted at the ends.
You have hardcoded widths and heights - including the fonts in pixels, this will make your app look very bad on high pixel density devices like the bold 3.
You are overriding a HorizontalFieldManager and then completely recreating the sublayout method. Better to simply extend the Manager class since you do not seem to using any facility of HorizontalFieldManager.
Remember that not all fields will give the correct getPreferredWidth/Height and you should only use these methods to make estimations during layout.
I would suggest that you rethink and rewrite your entire code after taking into account the different devices you would need to target. Use point based fonts and measurements instead of pixel based measurements.
All the best.
How to create three editfields like this
HorizontalFieldManager hfm_city=new HorizontalFieldManager();
VerticalFieldManager vfm_city = new VerticalFieldManager();
vfm_city.setBorder(
BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), borderBitmap
)
);
vfm_city.setMargin(0, 200, 0, 0);
final EditField city = new EditField("", "", 30, BasicEditField.FILTER_DEFAULT){
String emptyString = "City";
protected void paintBackground(Graphics g) {
g.setBackgroundColor(0xFFFFFF);
g.clear();
}
protected void paint(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0x000000);
test = super.getText();
if ( test == null || test.length() < 1 ) {
//g.setColor(Config.hint_colour);
g.drawText(emptyString, 0, 0);
}
super.paint(g);
} finally {
g.setColor(oldColor);
}
}
};
vfm_city.add(city);
VerticalFieldManager vfm_state = new VerticalFieldManager();
vfm_state.setBorder(
BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), borderBitmap
)
);
vfm_state.setMargin(0, 0, 0, 0);
final EditField state = new EditField("", "", 30, BasicEditField.FILTER_DEFAULT){
String emptyString = "State";
protected void paintBackground(Graphics g) {
g.setBackgroundColor(0xFFFFFF);
g.clear();
}
protected void paint(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0x000000);
test = super.getText();
if ( test == null || test.length() < 1 ) {
//g.setColor(Config.hint_colour);
g.drawText(emptyString, 0, 0);
}
super.paint(g);
} finally {
g.setColor(oldColor);
}
}
};
vfm_state.add(state);
VerticalFieldManager vfm_zip = new VerticalFieldManager();
vfm_zip.setBorder(
BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), borderBitmap
)
);
vfm_zip.setMargin(0, 0, 0, 0);
final EditField zip = new EditField("", "", 30, BasicEditField.FILTER_DEFAULT){
String emptyString = "Zip";
protected void paintBackground(Graphics g) {
g.setBackgroundColor(0xFFFFFF);
g.clear();
}
protected void paint(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0x000000);
test = super.getText();
if ( test == null || test.length() < 1 ) {
//g.setColor(Config.hint_colour);
g.drawText(emptyString, 0, 0);
}
super.paint(g);
} finally {
g.setColor(oldColor);
}
}
};
vfm_zip.add(zip);
hfm_city.add(vfm_city);
hfm_city.add(vfm_state);
hfm_city.add(vfm_zip);
You are going in the right way. but you have to give specific width & height to yourVerticalFieldManager otherwise it will take full width by default.
VerticalFieldManager vfm_city = new VerticalFieldManager() {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getwidth()/3,30);
setExtent(Display.getwidth()/3,30);
}
};
Do this in your State & city vfm and add in your hfm and try.
Check my answer
{
Border bdr = BorderFactory.createRoundedBorder(new XYEdges(4, 4, 4, 4),Border.STYLE_SOLID);
VerticalFieldManager vert=new VerticalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),Display.getHeight());
setExtent(Display.getWidth(),Display.getHeight());
}
};
HorizontalFieldManager hr=new HorizontalFieldManager(USE_ALL_HEIGHT)
{
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),50);
setExtent(Display.getWidth(),50);
}
};
hr.setBackground(BackgroundFactory.createSolidBackground(Color.GREEN));
EditField e1=new EditField(Field.FOCUSABLE|Field.FIELD_VCENTER){
protected void layout(int width, int height) {
super.layout(100,30);
setExtent(100,30);
}
};
EditField e2=new EditField(Field.FOCUSABLE|Field.FIELD_VCENTER){
protected void layout(int width, int height) {
super.layout(60,30);
setExtent(60,30);
}
};
EditField e3=new EditField(Field.FOCUSABLE|Field.FIELD_VCENTER){
protected void layout(int width, int height) {
super.layout(60,30);
setExtent(60,30);
}
};
e1.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
e2.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
e3.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
e1.setPadding(0, 0, 0, 10);
e2.setPadding(0, 0, 0, 20);
e3.setPadding(0, 0, 0, 10);
e1.setBorder(bdr);
e2.setBorder(bdr);
e3.setBorder(bdr);
hr.add(e1);
hr.add(e2);
hr.add(e3);
vert.add(hr);
add(vert);
}
I'm using ListField in Blackberry and unable to apply the row.setChangeListener.
Can anybody please help me?
Here is my code,
Friendship objFriendship = new Friendship();
friends = objFriendship.FetchFriends(AATTGlobals.CURRENT_USER.getUserID());
rows = new Vector();
for (int x = 0; x < friends.length; x++) {
String UserName = friends[x].getUserName();
ProfilePicture = MISC.FetchUserProfilePicture(friends[x].getProfilePicturePath());
String Location = friends[x].getLocation();
TableRowManager row = new TableRowManager();
row.add(new BitmapField(ProfilePicture));
LabelField task = new LabelField(UserName,DrawStyle.ELLIPSIS)
{
protected void paint(Graphics graphics) {
graphics.setColor(0x0099CCFF);
super.paint(graphics);
}
};
task.setFont(Font.getDefault().derive(Font.BOLD));
row.add(task);
row.add(new LabelField(Location,DrawStyle.ELLIPSIS)
{
protected void paint(Graphics graphics) {
graphics.setColor(0x0099CCFF);
super.paint(graphics);
}
}
);
row.setChangeListener( new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
Dialog.alert("Row Clicked #");
}
});
No any error message but setChangeListener doesn't fire, here is TableRowManager
Private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
public void drawRow(Graphics g, int x, int y, int width, int height) {
layout(width, height);
setPosition(x, y);
g.pushRegion(getExtent());
subpaint(g);
g.setColor(0x0099CCFF);
g.drawLine(0, 0, getPreferredWidth(), 0);
g.popContext();
}
protected void sublayout(int width, int height) {
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
Field field = getField(0);
layoutChild(field, 44, 44);
setPositionChild(field, 10, getRowHeight() / 4);
field = getField(1);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 70, getRowHeight() / 5);
field = getField(2);
layoutChild(field, field.getPreferredWidth(), fontHeight + 1);
setPositionChild(field, 70, (getRowHeight() / 2) + 5);
setExtent(preferredWidth, getPreferredHeight());
}
public int getPreferredWidth() {
return Graphics.getScreenWidth();
}
public int getPreferredHeight() {
return getRowHeight();
}
}
in tableRowManager add this
//for non touch
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
//for touch
protected boolean touchEvent(TouchEvent message) {
if (TouchEvent.CLICK == message.getEvent()) {
FieldChangeListener listener = getChangeListener();
if (null != listener)
listener.fieldChanged(this, 1);
}
return super.touchEvent(message);
}
try this let me know is it working or not.
I noticed, fieldChangeLister/FieldChanged isnt getting called with ListField UI [as it works for button and labels.]So I think FieldChanged is not supported with Listfield
In navigationClick/TouchEvent (), write the action you are writing in FieldChange method.
hi all The below is my code .i try to remove black border color from popup window .i tried this but still i get small black border .
public class S2SPopup extends PopupScreen
{
public S2SPopup()
{
super(new VerticalFieldManager()
{
public void paint(Graphics g)
{
int a = g.getGlobalAlpha();
int c = g.getColor();
g.setColor(c);
g.drawBitmap(0, 0, HomeScreen.popupimg.getWidth(),HomeScreen.popupimg.getHeight(),HomeScreen.popupimg, 0, 0);
super.paint(g);
}
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout( HomeScreen.popupimg.getWidth(),HomeScreen.popupimg.getHeight());
setExtent( HomeScreen.popupimg.getWidth(),HomeScreen.popupimg.getHeight());
}
});
setBackground(BackgroundFactory.createSolidTransparentBackground(Color.WHITE, 0));
VerticalFieldManager vfm_Label = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL)
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(maxWidth,150);
setExtent(maxWidth, 150);
}
};
vfm_Label.setMargin(80, 0, 0, 0);
ButtonField btnclose = new ButtonField("",ButtonField.RIGHT)
{
public void paint(Graphics g)
{
//setBackground(BackgroundFactory.createSolidTransparentBackground(Color.WHITE, 0));
int c = g.getGlobalAlpha();
g.setBackgroundColor(c);
super.paint(g);
}
};
btnclose.setMargin(0, 0, 0, 250);
btnclose.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context)
{
close();
}
});
LabelField s2sLabelField = new LabelField()
{
public void paint(Graphics g)
{
g.setColor(Color.BLUE);
super.paint(g);
}
protected void layout(int width, int height)
{
super.layout(width, 150);
setExtent(width, 150);
}
};
s2sLabelField.setPadding(0, 50, 0, 30);
s2sLabelField.setText("lasjdfljlsjlfj ljsfdl jsflljfiowurnowncnvouern.zvovn ljlsfdjj jlj" +
"jsljfdlj ljsfl sjfl jfjsljdfljslfu jsjf;ujerpljsfdjpn sdflsajf ss23s mail jsldfjlfdju nsfjljljlfjmnn,nsf,n,nlojljlsndf,n,ljnsjfdljjufsn jj" +
"sjfd;jjljlsduflja;sfj ljsldfujrqnfqperiujf.zvnpqrue 33333333333333333333333333333333333333 ");
add(btnclose);
vfm_Label.add(s2sLabelField);
add(vfm_Label);
} //end of constructor
} // end of main screen
Override applyTheme with an empty implementation, and the black border goes away. You can't fix this from the constructor alone:
protected void applyTheme(){}
I doubt that it will correct this, but you may try giving your delegate manager a margin of 0 just to be certain that there isn't one on it and background color is creeping in from the theme. A solution that I have implemented in the past is to create your own custom Screen
public class CustomPopup extends Screen {
public CustomPopup() {
super(new VerticalFieldManager() {
//your custom code or a custom manager class (which is what I did)
);
setBackground(BackgroundFactory.createSolidTransparentBackground(0x000000, 0));
}
protected void sublayout(int width, int height) {
//make this screen take up the entire display
setPosition(0, 0);
setExtent(Display.getWidth(), Display.getHeight());
//and layout the delegate
setPositionDelegate(some_x, some_y);
layoutDelegate(some_width, some_height);
}
}
You'll have to add your own buttons and other graphics to it, but This should at least help point you in the right direction.
I am trying to change the width and height of a BlackBerry BasicEditField.
But its not displaying the BasicEditField as i mention.
HorizontalFieldManager HFMreg =
new HorizontalFieldManager(
HorizontalFieldManager.USE_ALL_WIDTH
| HorizontalFieldManager.USE_ALL_HEIGHT) {
//Override the paint method to draw the background image.
public void paint(Graphics graphics) {
//Draw the registration background image
graphics.drawBitmap(0,0,Display.getWidth(),Display.getHeight(),BMregbg, 0, 0);
super.paint(graphics);
}
};
BEFfirstname = new BasicEditField("","",5,EditField.NO_NEWLINE) {
protected void paint(Graphics graphics) {
graphics.fillRect(0,0,80,25);
graphics.setBackgroundColor(Color.WHITE);
graphics.clear();
super.paint(graphics);
}
protected void layout() {
super.layout(getPreferredWidth(),getPreferredHeight());
setExtent(80,25); //width,height
}
public int getPreferredWidth() {
int fieldWidth = 80; //required width
return fieldWidth;
}
public int getPreferredHeight() {
int fieldHeight = 25; // required height
return fieldHeight;
}
};
//BEFfirstname.setMargin(200,0,0,60);
HFMreg.add(LFfirstname);
HFMreg.add(BEFfirstname);
add(HFMreg);
just an other way round:
BasicEditField BEFfirstname = new BasicEditField("","",5,EditField.NO_NEWLINE);
MyManager obj = new MyManger();
obj.add(BEFfirstname);
add(obj);
class MyManager extends Manager
{
MyManager()
{
super(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT);
}
protected void sublayout(int width, int height)
{
Field f = getField(0);
layoutChild(f,80,25);
setPositionChild(f, 10, 10);
}
}