Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
New Developer
fli
Posts: 3
Registered: ‎06-26-2009
My Device: Not Specified

VerticalFieldManager list hiding rows scrolling issue

My app has a VFM, it contains a list of ListItem that extends from VFM, each ListItem contains two rows, the 1st row is a LabelField and the 2nd row is a HFM, the HFM contains 2 LabelField and a NullField which is the only focusable field within each ListIte

when scroll down to hidden part of list which is not visiable from screen, only 1 row of the ListItem is displayed instead of the whole ListItem area (2 rows), how do I make both rows displayed on each scroll?

I have tried to override the SetExtent and Sublayout, did not have any successes.


import javax.microedition.io.*;
import java.io.*;
import javax.microedition.media.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.apps.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.device.api.util.*;
import net.rim.device.apps.api.framework.file.*;


public class HelloApp extends UiApplication{

//private ApplicationEntry _applicationEntry;
private LogScreen myHS;
public static void main(String argv[]) {

HelloApp app = new HelloApp();
app.enterEventDispatcher();
}

public HelloApp() {
myHS = new LogScreen();
pushScreen(myHS);

}
}

class LogScreen extends MainScreen /*implements FocusChangeListener*/{

private ListItem listItem;
VerticalFieldManager vfmMain;


LogScreen() {
super();
this.setTitle("Test App!");
vfmMain = new VerticalFieldManager(net.rim.device.api.ui.Manager.VERTICAL_SCROLLBAR | net.rim.device.api.ui.Manager.VERTICAL_SCROLL);

for(int i = 0; i < 8; i++) {

listItem = new ListItem(2, 0);
HorizontalFieldManager hfm = new HorizontalFieldManager(HorizontalFieldManager.NO_HORIZONTAL_SCROLL);

LabelField lf = new LabelField("Row" + i, Field.NON_FOCUSABLE | Field.USE_ALL_WIDTH );
LabelField label2 = new LabelField("Label_a" + i , Field.NON_FOCUSABLE );
LabelField label3 = new LabelField("label_b", Field.NON_FOCUSABLE | Field.USE_ALL_WIDTH);

hfm.add(label2);
hfm.add(label3);
hfm.add(new NullField(NullField.FOCUSABLE));

listItem.add(lf);
listItem.add(hfm);

vfmMain.add(listItem);
}
}
}

class ListItem extends VerticalFieldManager {

private int _numTextRows;
private long style;
public static int _screenWidth = Display.getWidth() ;


public ListItem(int numRows, long style) {

super(VerticalFieldManager.NO_VERTICAL_SCROLL);

_numTextRows = numRows;


}


public int getPreferredWidth() {
return _screenWidth;
}

public int getPreferredHeight() {
int height = Font.getDefault().getHeight() * _numTextRows;
return height;
}

protected void onUnfocus() {
super.onUnfocus();
System.out.println("LCListItem onUnfocus()!");
invalidate();
}

public boolean isFocusable() {
System.out.println("LCListItem isFocusable()!");
return true;
}


protected void onFocus(int direction) {
super.onFocus(direction);
System.out.println("LCListItem onFocus()!");
invalidate();
}


public void paint(Graphics g)
{

if (this.isFocus()) {
g.setBackgroundColor(Color.BLUE);
g.clear();
} else {
g.setBackgroundColor(Color.WHITE);
g.clear();
}
super.paint(g);
}
}

 


 


Developer
konic
Posts: 173
Registered: ‎06-11-2009
My Device: Not Specified

Re: VerticalFieldManager list hiding rows scrolling issue

[ Edited ]
Ppl will see nothing unless you add the line:

add (vfmMain);

 at the end of the LogScreen constructor :smileyhappy:

Message Edited by konic on 06-27-2009 07:12 AM
Developer
konic
Posts: 173
Registered: ‎06-11-2009
My Device: Not Specified

Re: VerticalFieldManager list hiding rows scrolling issue

[ Edited ]
OK,
I see nobody steps forware with the solution, so here it is.
It is just an idea which should be polished, but it works.
Fix the height of that VerticalFieldManager vfmMain of yours:

static private ListItem listItem;
...
static int listHeight;

vfmMain = new VerticalFieldManager(Manager.VERTICAL_SCROLLBAR | Manager.VERTICAL_SCROLL) {
public int getPreferredHeight()
{
return listHeight;
}

protected void sublayout(int width, int height)
{
super.sublayout(width, listHeight);
setExtent(width, listHeight);
}
};

 Next, add ScrollListener

vfmMain.setScrollListener(new MyScroll());

 And that MyScroll class itself into the LogScreen class:

private static int oldScroll = 0;
private class MyScroll implements ScrollChangeListener {
public void scrollChanged(Manager manager, int newHorizontalScroll,
int newVerticalScroll) {
int h = listItem.getHeight();
int res = newVerticalScroll % h;
if ( res > 0 )
{
if (newVerticalScroll > oldScroll)
manager.setVerticalScroll(newVerticalScroll + h - res);
else
manager.setVerticalScroll(newVerticalScroll - res);
}
else
oldScroll = newVerticalScroll;
}
}

 To specify listHeight I used height of the default font:

Font f = Font.getDefault();
int h = f.getHeight();
listHeight = h*8; // 4 - tuple rows

 That's it :smileyhappy:

Message Edited by konic on 06-27-2009 04:01 PM
New Developer
New Developer
fli
Posts: 3
Registered: ‎06-26-2009
My Device: Not Specified

Re: VerticalFieldManager list hiding rows scrolling issue

Thanks, I tried your suggestion and can't see my list items any more. Where will the oldScroll be used other than the nested class?

import javax.microedition.io.*; import java.io.*; import javax.microedition.media.*; import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.apps.api.ui.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.system.*; import net.rim.device.api.util.*; import net.rim.device.apps.api.framework.file.*; import net.rim.device.api.ui.Manager.*; public class HelloApp extends UiApplication{ //private ApplicationEntry _applicationEntry; private LogScreen myHS; public static void main(String argv[]) { HelloApp app = new HelloApp(); app.enterEventDispatcher(); } public HelloApp() { myHS = new LogScreen(); pushScreen(myHS); } } class LogScreen extends MainScreen /*implements FocusChangeListener*/{ static private MyListItem listItem; VerticalFieldManager vfmMain; static int listHeight; private static int oldScroll = 0; LogScreen() { super(); this.setTitle("Test App!"); Font f = Font.getDefault(); int h = f.getHeight(); listHeight = h*2; // 4 - tuple rows vfmMain = new VerticalFieldManager(net.rim.device.api.ui.Manager.VERTICAL_SCROLLBAR | net.rim.device.api.ui.Manager.VERTICAL_SCROLL) { public int getPreferredHeight() { return listHeight; } protected void sublayout(int width, int height) { super.sublayout(width, listHeight); setExtent(width, listHeight); } }; for(int i = 0; i < 8; i++) { listItem = new MyListItem(2, 0); HorizontalFieldManager hfm = new HorizontalFieldManager(HorizontalFieldManager.NO_HORIZONTAL_SCROLL); LabelField lf = new LabelField("Row" + i, Field.NON_FOCUSABLE | Field.USE_ALL_WIDTH ); LabelField label2 = new LabelField("Label_a" + i , Field.NON_FOCUSABLE ); LabelField label3 = new LabelField("label_b", Field.NON_FOCUSABLE | Field.USE_ALL_WIDTH); hfm.add(label2); hfm.add(label3); hfm.add(new NullField(NullField.FOCUSABLE)); listItem.add(lf); listItem.add(hfm); vfmMain.add(listItem); } vfmMain.setScrollListener(new MyScroll()); add(vfmMain); } private static class MyScroll implements ScrollChangeListener { public void scrollChanged(net.rim.device.api.ui.Manager manager, int newHorizontalScroll, int newVerticalScroll) { int h = listItem.getHeight(); int res = newVerticalScroll % h; if ( res > 0 ) { if (newVerticalScroll > oldScroll) manager.setVerticalScroll(newVerticalScroll + h - res); else manager.setVerticalScroll(newVerticalScroll - res); } else oldScroll = newVerticalScroll; } } } class MyListItem extends VerticalFieldManager { private int _numTextRows; private long style; public static int _screenWidth = Display.getWidth() ; public MyListItem(int numRows, long style) { super(VerticalFieldManager.NO_VERTICAL_SCROLL); _numTextRows = numRows; } public int getPreferredWidth() { return _screenWidth; } public int getPreferredHeight() { int height = Font.getDefault().getHeight() * _numTextRows; return height; } protected void onUnfocus() { super.onUnfocus(); System.out.println("MyListItem onUnfocus()!"); invalidate(); } public boolean isFocusable() { System.out.println("MyListItem isFocusable()!"); return true; } protected void onFocus(int direction) { super.onFocus(direction); System.out.println("MyListItem onFocus()!"); invalidate(); } public void paint(Graphics g) { if (this.isFocus()) { g.setBackgroundColor(Color.BLUE); g.clear(); } else { g.setBackgroundColor(Color.WHITE); g.clear(); } super.paint(g); } }

 

Developer
konic
Posts: 173
Registered: ‎06-11-2009
My Device: Not Specified

Re: VerticalFieldManager list hiding rows scrolling issue

OK,
here is the full code, I called it TwoRows :smileyhappy: :

import java.io.*;

import javax.microedition.io.*;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;
import net.rim.device.api.system.*;
import net.rim.device.api.util.*;


public class TwoRows extends UiApplication{

//private ApplicationEntry _applicationEntry;
private LogScreen myHS;

public static void main(String argv[]) {
TwoRows app = new TwoRows();
app.enterEventDispatcher();
}

public TwoRows() {
myHS = new LogScreen();
pushScreen(myHS);
}
}

class LogScreen extends MainScreen {

static private ListItem listItem;
VerticalFieldManager vfmMain;
static int listHeight;

LogScreen() {
super();
this.setTitle("TwoRows");

Font f = Font.getDefault();
int h = f.getHeight();
listHeight = h*8;

vfmMain = new VerticalFieldManager(Manager.VERTICAL_SCROLLBAR | Manager.VERTICAL_SCROLL) {
public int getPreferredHeight()
{
return listHeight;
}

protected void sublayout(int width, int height)
{
super.sublayout(width, listHeight);
setExtent(width, listHeight);
}
};
vfmMain.setScrollListener(new MyScroll());

for(int i = 0; i < 8; i++) {

listItem = new ListItem(2, 0);
HorizontalFieldManager hfm = new HorizontalFieldManager(HorizontalFieldManager.NO_HORIZONTAL_SCROLL);

LabelField lf = new LabelField("Row" + i, Field.NON_FOCUSABLE | Field.USE_ALL_WIDTH );
LabelField label2 = new LabelField("Label_a" + i , Field.NON_FOCUSABLE );
LabelField label3 = new LabelField("label_b", Field.NON_FOCUSABLE | Field.USE_ALL_WIDTH);

hfm.add(label2);
hfm.add(label3);
hfm.add(new NullField(NullField.FOCUSABLE));

listItem.add(lf);
listItem.add(hfm);

vfmMain.add(listItem);
}
add (vfmMain);
}

private static int oldScroll = 0;
private class MyScroll implements ScrollChangeListener {
public void scrollChanged(Manager manager, int newHorizontalScroll,
int newVerticalScroll) {
int h = listItem.getHeight();
int res = newVerticalScroll % h;
if ( res > 0 )
{
if (newVerticalScroll > oldScroll)
manager.setVerticalScroll(newVerticalScroll + h - res);
else
manager.setVerticalScroll(newVerticalScroll - res);
}
else
oldScroll = newVerticalScroll;
}
}

} // class LogScreen

class ListItem extends VerticalFieldManager {

private int _numTextRows;
private long style;
public static int _screenWidth = Display.getWidth() ;

public ListItem(int numRows, long style) {

super(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR);
_numTextRows = numRows;
}

public int getPreferredWidth() {
return _screenWidth;
}

public int getPreferredHeight() {
int height = Font.getDefault().getHeight() * _numTextRows;
return height;
}

protected void onUnfocus() {
super.onUnfocus();
//System.out.println("LCListItem onUnfocus()!");
invalidate();
}

public boolean isFocusable() {
//System.out.println("LCListItem isFocusable()!");
return true;
}

protected void onFocus(int direction) {
super.onFocus(direction);
//System.out.println("LCListItem onFocus()!");
invalidate();
}

public void paint(Graphics g)
{
if (this.isFocus()) {
g.setBackgroundColor(Color.BLUE);
g.clear();
} else {
g.setBackgroundColor(Color.WHITE);
g.clear();
}
super.paint(g);
}
}

 

New Developer
New Developer
fli
Posts: 3
Registered: ‎06-26-2009
My Device: Not Specified

Re: VerticalFieldManager list hiding rows scrolling issue

Thanks a lot for your help. I tried to make more rows visible to fit the whole screen height by doubling listHeight, and I still see the same proflem, each time I scroll to a listItem that is previous hidden, it only scroll one row instead the whole list items(2 rows). I am using a 4.7 JDE with 9000 bold simulator

import java.io.*; import javax.microedition.io.*; import net.rim.device.api.ui.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.decor.Border; import net.rim.device.api.ui.decor.BorderFactory; import net.rim.device.api.system.*; import net.rim.device.api.util.*; public class TwoRows extends UiApplication{ //private ApplicationEntry _applicationEntry; private LogScreen myHS; public static void main(String argv[]) { TwoRows app = new TwoRows(); app.enterEventDispatcher(); } public TwoRows() { myHS = new LogScreen(); pushScreen(myHS); } } class LogScreen extends MainScreen { static private ListItem listItem; VerticalFieldManager vfmMain; static int listHeight; LogScreen() { super(); this.setTitle("TwoRows"); Font f = Font.getDefault(); int h = f.getHeight(); listHeight = h*16; vfmMain = new VerticalFieldManager(Manager.VERTICAL_SCROLLBAR | Manager.VERTICAL_SCROLL) { public int getPreferredHeight() { return listHeight; } protected void sublayout(int width, int height) { super.sublayout(width, listHeight); setExtent(width, listHeight); } }; vfmMain.setScrollListener(new MyScroll()); for(int i = 0; i < 8; i++) { listItem = new ListItem(2, 0); HorizontalFieldManager hfm = new HorizontalFieldManager(HorizontalFieldManager.NO_HORIZONTAL_SCROLL); LabelField lf = new LabelField("Row " + i, Field.NON_FOCUSABLE | Field.USE_ALL_WIDTH ); LabelField label2 = new LabelField(" Label_a" + i , Field.NON_FOCUSABLE ); LabelField label3 = new LabelField(" label_b", Field.NON_FOCUSABLE | Field.USE_ALL_WIDTH); hfm.add(label2); hfm.add(label3); hfm.add(new NullField(NullField.FOCUSABLE)); listItem.add(lf); listItem.add(hfm); System.out.println("added row " + i); vfmMain.add(listItem); } add (vfmMain); } private static int oldScroll = 0; private class MyScroll implements ScrollChangeListener { public void scrollChanged(Manager manager, int newHorizontalScroll, int newVerticalScroll) { int h = listItem.getHeight(); int res = newVerticalScroll % h; System.out.println("h: " + h + " res: " + res + " newVerticalScroll: " + newVerticalScroll); if ( res > 0 ) { if (newVerticalScroll > oldScroll) manager.setVerticalScroll(newVerticalScroll + h - res); else manager.setVerticalScroll(newVerticalScroll - res); } else oldScroll = newVerticalScroll; } } } // class LogScreen class ListItem extends VerticalFieldManager { private int _numTextRows; private long style; public static int _screenWidth = Display.getWidth() ; public ListItem(int numRows, long style) { super(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR); _numTextRows = numRows; } public int getPreferredWidth() { return _screenWidth; } public int getPreferredHeight() { int height = Font.getDefault().getHeight() * _numTextRows; return height; } protected void onUnfocus() { super.onUnfocus(); //System.out.println("LCListItem onUnfocus()!"); invalidate(); } public boolean isFocusable() { //System.out.println("LCListItem isFocusable()!"); return true; } protected void onFocus(int direction) { super.onFocus(direction); //System.out.println("LCListItem onFocus()!"); invalidate(); } public void paint(Graphics g) { if (this.isFocus()) { g.setBackgroundColor(Color.BLUE); g.clear(); } else { g.setBackgroundColor(Color.WHITE); g.clear(); } super.paint(g); } }

 

Contributor
raj_eemtec
Posts: 10
Registered: ‎09-18-2012
My Device: 9650

Re: VerticalFieldManager list hiding rows scrolling issue

I tried your solution. it works great in simulator.

 

But when i tried it in device it's jerking. and the scoll is not smooth.

 

Do you have any other solutions.

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: VerticalFieldManager list hiding rows scrolling issue

thread-necromancy won't help you get an answer, the OP was last active in 2009. Please open your own thread the next time.

to still answer your question: use ListField.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: VerticalFieldManager list hiding rows scrolling issue

Try adding this in the ListItem code:

public void getFocusRect(XYRect rect) {
  rect.x = 0;
  rect.y = 0;
  rect.width = getWidth();
  rect.height = getHeight();
}

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Contributor
raj_eemtec
Posts: 10
Registered: ‎09-18-2012
My Device: 9650

Re: VerticalFieldManager list hiding rows scrolling issue

Thanks for ur responnse. I tried ur solution still the same problem. i am new to Blackberry development. can u please help me to fix this.