12-06-2012 06:15 AM
Hello sir
i want to scroll list horizontally i know it is possible ..actually my list is scrolling vertically ...can it possible to scroll horizontal..? is i have more column ? actually i have this time 4 column of width =device.getwidth/4. is i have five columm of same width how to scroll horizontally ?
I have using this code...
package com.black.applicationloader; import java.util.Vector; import net.rim.device.api.system.Display; import net.rim.device.api.system.KeypadListener; 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.Keypad; import net.rim.device.api.ui.Manager; import net.rim.device.api.ui.UiApplication; 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) { if(colourList_1 == getLeafFieldWithFocus()){ if(key=='t'||key=='T'){ colourList_2.setFocus(); } return true; } else{ return super.keyChar(key,status,time); } }; protected void drawFocus(Graphics graphics, boolean on) { hasFocus = on; 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); } protected boolean navigationMovement(int dx, int dy, int status, int time) { if(dy > 0 && (status & KeypadListener.STATUS_FOUR_WAY) == KeypadListener.STATUS_FOUR_WAY && (status & KeypadListener.STATUS_ALT) == KeypadListener.STATUS_ALT) { // do stuff colourList_2.setFocus(); return true; // if you want the field to consume this event } return super.navigationMovement(dx, dy, 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 = on; super.drawFocus(graphics, on); hasFocus = false; } protected boolean keyChar(char key, int status, int time) { if(colourList_2 == getLeafFieldWithFocus()){ //if(key=='t'||key=='T'){ if(key=='t'){ colourList_1.setFocus(); colourList_1.setSelectedIndex(0); } return true; } else{ return super.keyChar(key,status,time); } } protected boolean navigationMovement(int dx, int dy, int status, int time) { if(dy < 0 && (status & KeypadListener.STATUS_FOUR_WAY) == KeypadListener.STATUS_FOUR_WAY && (status & KeypadListener.STATUS_ALT) == KeypadListener.STATUS_ALT) { // do stuff colourList_1.setFocus(); return true; // if you want the field to consume this event } return super.navigationMovement(dx, dy, 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(); } }
12-06-2012 06:42 AM
Have you researched this? I seem to remember that someone else has asked the same question previously.
12-06-2012 06:51 AM
actually some one told me to check dx if dx is greater than >o than move horizontally
, but i don't know where to check dx..? in this method navigationMovement.?
12-06-2012 08:19 AM
Yes.
12-06-2012 11:30 AM
hello
protected boolean navigationMovement(int dx, int dy, int status, int time) {
if(dx>0){
how to scroll list ?
}
}
12-06-2012 01:41 PM
Try putting the ListField in a HorizontalFieldManager. You will have to make sure that you override the ListField's getPreferredWidth to return the width you want. And the column width you specify should not be Display.getWidth()/<number of columns>. Calculate that in drawListRow based on the width that you get there.
Having done this, see if swiping or moving the trackpad will scroll the ListField left and right.
I suggest you try this in a sample screen using a simple ListField first without all your other embellishments. Once you have the process working for the Simple ListField, you are repeat the exercise with your real ListFields.
And the other advantage of creating a simple test version of this is that there is less code to paste in here and if you do paste code in here then we have a chance of running it ourselves.
Good luck.
12-07-2012 01:08 AM
Hello
sir i try this but not getting success..
can you please check my code...
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.component.ListField; import net.rim.device.api.ui.component.ListFieldCallback; import net.rim.device.api.ui.container.HorizontalFieldManager; import net.rim.device.api.ui.container.MainScreen; public class Blacktest extends MainScreen implements ListFieldCallback{ private static final String[] _elements = {"First element", "Second element", "Third element", "Fourth element", "Fifth element"}; private Vector _listElements = new Vector(_elements.length, 1); private ListField colourList_1; Blacktest(){ HorizontalFieldManager hfm =new HorizontalFieldManager(Manager.HORIZONTAL_SCROLL|M anager.VERTICAL_SCROLL){ protected void sublayout(int maxWidth, int maxHeight) { // TODO Auto-generated method stub super.sublayout( maxWidth, 2*colourList_1.getRowHeight()); setExtent(maxWidth,2*colourList_1.getRowHeight()); } }; colourList_1 = new ListField(); colourList_1.setCallback(this); int elementLength = _elements.length; for(int count = 0; count < elementLength; ++count) { colourList_1.insert(count); this.insert(_elements[count], count); } hfm.add(colourList_1); add(hfm); } public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width) { int columnWidth=160; 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 500; } 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(); } }
12-07-2012 03:33 AM
Till now i am not able to do that...
12-07-2012 08:16 AM
Sorry bit busy atm. Will look at this latter. I can't promise when, but if no one else steps in to solve this, I will try to get you an answer by this time tomorrow if not sooner... Fingers crossed.
One thing to try, this looks wrong:
protected void sublayout(int maxWidth, int maxHeight) {
// TODO Auto-generated method stub
super.sublayout( maxWidth, 2*colourList_1.getRowHeight());
setExtent(maxWidth,2*colourList_1.getRowHeight());
}
Let the HFM sort out the height it wants, you need to set the width.
In fact I think my previous advice to you was correct but not helpful. Instead move
columnWidth
back into the mainline and set it to the size you want. Then in sublayout for the HFM, set the maxWidth to, say 5 * that width, so you get space for 5 columns.
You are aware that the scrolling will impact both ListFields? This is what you want?
12-07-2012 10:07 AM
Actually That screen i have only one listfield ...I want to scroll that list horizontally as well as vertically bz i have large number of column ...
if you get solution please update me..
Thanks