12-04-2012 07:52 AM
How to add space in between two listfied .?
How to go one listfield to another using alt button ?
package com.black.applicationloader;
import java.util.Vector;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;
import net.rim.device.api.ui.container.VerticalFieldManag
import com.black.blackinterface.BlackInterface;
import com.black.common.BaseScreen;
import com.black.components.CustomEditField;
import com.black.utility.Utilities;
public class BlackSecondScreen extends BaseScreen implements BlackInterface,ListFieldCallback {
private VerticalFieldManager listFieldManager;
private VerticalFieldManager listFieldManager_2;
private static final String[] _elements = {"First element", "Second element", "Third element", "Fourth element", "Fifth element"};
private Vector _listElements = new Vector(_elements.length, 1);
int columnWidth = Display.getWidth()/4;
private boolean hasFocus; // =false
private CustomEditField userEditField;
ListField colourList_1;
ListField colourList_2;
BlackSecondScreen(){
colourList_1 = new ListField(){
protected void drawFocus(Graphics graphics, boolean on) {
XYRect rect = new XYRect();
graphics.setGlobalAlpha(200);
getFocusRect(rect);
drawHighlightRegion(graphics,HIGHLIGHT_FOCUS,true,
}
public void onFocus(int direction) {
hasFocus = true;
super.onFocus(direction);
}
// Invoked when a field loses the focus.
public void onUnfocus() {
hasFocus = false;
super.onUnfocus();
invalidate();
}
public int moveFocus(int amount, int status, int time) {
invalidate(getSelectedIndex());
return super.moveFocus(amount, status, time);
}
};
colourList_1.setCallback(this);
int elementLength = _elements.length;
for(int count = 0; count < elementLength; ++count)
{
colourList_1.insert(count);
this.insert(_elements[count], count);
}
colourList_2 = new ListField(){
protected void drawFocus(Graphics graphics, boolean on) {
XYRect rect = new XYRect();
graphics.setGlobalAlpha(200);
getFocusRect(rect);
drawHighlightRegion(graphics,HIGHLIGHT_FOCUS,true,
}
public void onFocus(int direction) {
hasFocus = true;
super.onFocus(direction);
}
// Invoked when a field loses the focus.
public void onUnfocus() {
hasFocus = false;
super.onUnfocus();
invalidate();
}
public int moveFocus(int amount, int status, int time) {
invalidate(getSelectedIndex());
return super.moveFocus(amount, status, time);
}
};
colourList_2.setCallback(this);
for(int count = 0; count < elementLength; ++count)
{
colourList_2.insert(count);
this.insert(_elements[count], count);
}
//add(colourList);
createComponents();
layoutComponents();
}
public void createComponents() {
listFieldManager= new VerticalFieldManager(Manager.VERTICAL_SCROLL|Manag
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout( maxWidth, 2*colourList_1.getRowHeight());
setExtent(maxWidth,2*colourList_1.getRowHeight());
};
};
listFieldManager_2= new VerticalFieldManager(Manager.VERTICAL_SCROLL|Manag
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout( maxWidth, 2*colourList_2.getRowHeight());
setExtent(maxWidth,2*colourList_2.getRowHeight());
};
};
// userEditField=new CustomEditField(Utilities.getAdjustedWidth(150),
// Utilities.getAdjustWidth(2), Manager.NO_HORIZONTAL_SCROLL
// | Manager.VERTICAL_SCROLL, true);
}
public void layoutComponents() {
// TODO Auto-generated method stub
listFieldManager.add(colourList_1);
listFieldManager_2.add(colourList_2);
add(listFieldManager);
add(listFieldManager_2);
}
public void initializeListeners() {
// TODO Auto-generated method stub
}
public void setComponentsXYMargins() {
// TODO Auto-generated method stub
}
public void drawListRow(ListField listField, Graphics graphics, int index,
int y, int width) {
int curSelected;
if (hasFocus) {
curSelected = listField.getSelectedIndex();
} else {
curSelected = -1;
}
if(index%2 == 0 ){
graphics.setColor(Color.PERU);
graphics.fillRect(0, y, width, listField.getRowHeight());
}else{
graphics.setColor(Color.WHEAT);
graphics.fillRect(0, y, width, listField.getRowHeight());
}
//graphics.fillRect(0,0,width,y);
int xpos = 0;int ypos = 0;
graphics.setFont(Font.getDefault());// please set a font value
// this is first column text
graphics.setColor(Color.BLACK);
graphics.drawText("column1"+index,xpos,y);
xpos += columnWidth;
graphics.setColor(Color.RED);
graphics.drawText("column2",xpos,y);
xpos += columnWidth;
graphics.drawText("column3",xpos,y);
xpos += columnWidth;
graphics.drawText("column4",xpos,y);
}
public Object get(ListField listField, int index) {
// TODO Auto-generated method stub
return _listElements.elementAt(index);
}
public int getPreferredWidth(ListField listField) {
// TODO Auto-generated method stub
return Graphics.getScreenWidth();
}
public int indexOfList(ListField listField, String prefix, int start) {
// TODO Auto-generated method stub
return _listElements.indexOf(prefix, start);
}
public void insert(String toInsert, int index)
{
_listElements.insertElementAt(toInsert, index);
}
public void erase()
{
_listElements.removeAllElements();
}
}
Solved! Go to Solution.
12-04-2012 08:25 AM
12-04-2012 11:54 AM
Hi any other method to to space in between two list field.
for my suggestion :increase the size of manager (sublayout size example 200 height) and list field (layout method height 100)..may be there is difference 100 px in between the second fiels may i correct..?
Please suggest me how to do go one list field to another listfield on pressing any button? actually i have two listfield in my screen can you please tell me how to switch one listfield to another ?
Thanks
12-05-2012 12:27 AM
As explained before by simon setMargin is the best method to do this. All you need to do is eg:
hfm is intsnce of your manager.
the only thing you need to do is
hfm.setMargin(int top,int right,int bottom,it left);
no you want spce between 2 managers say hfm,hfm1 .
So you need to just have
hfm.setMargin(10,0,10,0);
this will set margin on top of ur manager where you add list field and to bottom .
12-05-2012 12:36 AM
12-05-2012 12:44 AM
12-05-2012 01:27 AM
Hello
actually i have 2 listfield in my screen .i want to to toggle the focus(between listfield) on pressing any button example (alt).actually the problem is that in blackberry there is defult functionality focus never go to next field till it complete the first . example if there is 50 element in listfield user never goes to next list field (which is below first) till it scroll last element in row.
so i want if user click alt button it goes to below listfield .if user again press same alt button it goes to upper list above this.
Thanks
12-05-2012 02:48 AM
12-05-2012 03:54 AM
Hi
Not able to understant please explain..
12-05-2012 04:33 AM
package com.black.applicationloader; import java.util.Vector; import net.rim.device.api.system.Display; import net.rim.device.api.ui.Color; import net.rim.device.api.ui.Font; import net.rim.device.api.ui.Graphics; import net.rim.device.api.ui.Manager; import net.rim.device.api.ui.XYRect; import net.rim.device.api.ui.component.Dialog; import net.rim.device.api.ui.component.ListField; import net.rim.device.api.ui.component.ListFieldCallback; import net.rim.device.api.ui.container.VerticalFieldManager; import com.black.blackinterface.BlackInterface; import com.black.common.BaseScreen; import com.black.components.CustomEditField; import com.black.utility.Utilities; public class BlackSecondScreen extends BaseScreen implements BlackInterface,ListFieldCallback { private VerticalFieldManager listFieldManager; private VerticalFieldManager listFieldManager_2; private static final String[] _elements = {"First element", "Second element", "Third element", "Fourth element", "Fifth element"}; private Vector _listElements = new Vector(_elements.length, 1); int columnWidth = Display.getWidth()/4; private boolean hasFocus; // =false private CustomEditField userEditField; ListField colourList_1; ListField colourList_2; BlackSecondScreen(){ colourList_1 = new ListField(){ protected boolean keyChar(char key, int status, int time) { //Dialog.alert(""+key); return true; }; protected boolean keyDown(int keycode, int time) { Dialog.alert(""+keycode); return true; }; protected boolean keyUp(int keycode, int time) { //Dialog.alert(""+keycode); return true; }; protected void drawFocus(Graphics graphics, boolean on) { hasFocus = true; super.drawFocus(graphics, on); // XYRect rect = new XYRect(); // graphics.setGlobalAlpha(200); // getFocusRect(rect); // drawHighlightRegion(graphics,HIGHLIGHT_FOCUS,true, rect.x,rect.y,rect.width,rect.height); } public void onFocus(int direction) { hasFocus = true; super.onFocus(direction); } // Invoked when a field loses the focus. public void onUnfocus() { hasFocus = false; super.onUnfocus(); invalidate(); } public int moveFocus(int amount, int status, int time) { invalidate(getSelectedIndex()); return super.moveFocus(amount, status, time); } }; colourList_1.setCallback(this); int elementLength = _elements.length; for(int count = 0; count < elementLength; ++count) { colourList_1.insert(count); this.insert(_elements[count], count); } colourList_2 = new ListField(){ protected void drawFocus(Graphics graphics, boolean on) { //hasFocus = true; super.drawFocus(graphics, on); //hasFocus = false; // XYRect rect = new XYRect(); // graphics.setGlobalAlpha(200); // getFocusRect(rect); // drawHighlightRegion(graphics,HIGHLIGHT_FOCUS,true, rect.x,rect.y,rect.width,rect.height); } public void onFocus(int direction) { hasFocus = true; super.onFocus(direction); } // Invoked when a field loses the focus. public void onUnfocus() { hasFocus = false; super.onUnfocus(); invalidate(); } public int moveFocus(int amount, int status, int time) { invalidate(getSelectedIndex()); return super.moveFocus(amount, status, time); } }; colourList_2.setCallback(this); for(int count = 0; count < elementLength; ++count) { colourList_2.insert(count); this.insert(_elements[count], count); } //add(colourList); createComponents(); layoutComponents(); } public void createComponents() { listFieldManager= new VerticalFieldManager(Manager.VERTICAL_SCROLL|Manag er.HORIZONTAL_SCROLL){ protected void sublayout(int maxWidth, int maxHeight) { super.sublayout( maxWidth, 2*colourList_1.getRowHeight()); setExtent(maxWidth,2*colourList_1.getRowHeight()); }; }; listFieldManager_2= new VerticalFieldManager(Manager.VERTICAL_SCROLL|Manag er.HORIZONTAL_SCROLL){ protected void sublayout(int maxWidth, int maxHeight) { super.sublayout( maxWidth, 2*colourList_2.getRowHeight()); setExtent(maxWidth,2*colourList_2.getRowHeight()); }; }; // userEditField=new CustomEditField(Utilities.getAdjustedWidth(150), // Utilities.getAdjustWidth(2), Manager.NO_HORIZONTAL_SCROLL // | Manager.VERTICAL_SCROLL, true); } public void layoutComponents() { // TODO Auto-generated method stub listFieldManager.add(colourList_1); listFieldManager_2.add(colourList_2); listFieldManager.setMargin(0,0,40,0); add(listFieldManager); add(listFieldManager_2); } public void initializeListeners() { // TODO Auto-generated method stub } public void setComponentsXYMargins() { // TODO Auto-generated method stub } public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width) { int curSelected; if(!hasFocus){ if(index%2 == 0){ graphics.setColor(Color.RED); graphics.fillRect(0, y, width, listField.getRowHeight()); graphics.setColor(Color.WHITE); }else{ graphics.setColor(Color.BLACK); graphics.fillRect(0, y, width, listField.getRowHeight()); } } //graphics.fillRect(0,0,width,y); int xpos = 0;int ypos = 0; graphics.setFont(Font.getDefault());// please set a font value // this is first column text graphics.setColor(Color.PINK); graphics.drawText("column1"+index,xpos,y); xpos += columnWidth; //graphics.setColor(Color.RED); graphics.drawText("column2",xpos,y); xpos += columnWidth; graphics.drawText("column3",xpos,y); xpos += columnWidth; graphics.drawText("column4",xpos,y); } public Object get(ListField listField, int index) { // TODO Auto-generated method stub return _listElements.elementAt(index); } public int getPreferredWidth(ListField listField) { // TODO Auto-generated method stub return Graphics.getScreenWidth(); } public int indexOfList(ListField listField, String prefix, int start) { // TODO Auto-generated method stub return _listElements.indexOf(prefix, start); } public void insert(String toInsert, int index) { _listElements.insertElementAt(toInsert, index); } public void erase() { _listElements.removeAllElements(); } }
i am using this code not able to go next screen..![]()