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
Trusted Contributor
Posts: 182
Registered: ‎09-22-2011
My Device: 9700
My Carrier: airtel
Accepted Solution

Listfield.invalidate() not working properly

I am using a Customized Listfield where i am fetching content from the server and putting.I am displaying an image and a text in each row.The problem i am facing is that,after the images has been loaded,it doesnt get reflected.I have to scroll to see the effect.I have used  listnew.getManager().invalidate()  laso,but no use.Please help

Developer
Posts: 16,791
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Listfield.invalidate() not working properly

you have to set the list contents anew (re-populate teh underlying data structure). invalidate does not do that.
----------------------------------------------------------
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
Trusted Contributor
Posts: 182
Registered: ‎09-22-2011
My Device: 9700
My Carrier: airtel

Re: Listfield.invalidate() not working properly

I am populating the listfield,and in the vector i can see the datas,its get loaded also,but the problem is that it doesnt get reflected automatically,wen i scrool down one row by another,i mages start to show up.So the problem is not with populating the listfield but with repainting of the listfield and d manager automatically

Highlighted
Developer
Posts: 543
Registered: ‎12-23-2010
My Device: Z10
My Carrier: Airtel

Re: Listfield.invalidate() not working properly

Hi,

 

Try like this,

 

UiApplication.getUiApplication.getActiveScreen().invalidate() after downloading the image.

 

Thanks.

Trusted Contributor
Posts: 182
Registered: ‎09-22-2011
My Device: 9700
My Carrier: airtel

Re: Listfield.invalidate() not working properly

The problem still persists

Developer
Posts: 543
Registered: ‎12-23-2010
My Device: Z10
My Carrier: Airtel

Re: Listfield.invalidate() not working properly

Then may be the problem not with the repaint. can you post small snippet, then i can help you

Trusted Contributor
Posts: 182
Registered: ‎09-22-2011
My Device: 9700
My Carrier: airtel

Re: Listfield.invalidate() not working properly

listnew.setCallback(this);
rows = new Vector();
for (int x = 0; x < mSCtaegory.size(); x++) {
Hashtable hs = (Hashtable) mSCtaegory.elementAt(x);
row = new TableRowManager();
FontFamily fontFamily[] = FontFamily.getFontFamilies();
Font font = fontFamily[1].getFont(FontFamily.UNKNOWN_FONT, 13);
HTTPManager engine = new HTTPManager();
BitmapField bitmap = new BitmapField(Bitmap.getBitmapResource("30x30.png"));
HTTPGetTask img = new HTTPGetTask(this, (String) hs.get("img"), bitmap, 30, 30);
img.go();
row.add(bitmap);

LabelField task = new LabelField(hs.get("title"), LabelField.USE_ALL_WIDTH) {
public void paint(Graphics g) {
g.setColor(0x9e0a62);
super.paint(g);
}
protected void layout(int width, int height) {

super.layout(width, height);
setExtent(Display.getWidth(), Display.getHeight());
}
};
task.setFont(font);
row.add(task);
rows.addElement(row);
}
listnew.setSize(rows.size());
FontFamily fontFamilynew[] = FontFamily.getFontFamilies();
Font fontnew = fontFamilynew[1].getFont(FontFamily.SFF4_FONT, 16);
headertitle = new LabelField(title, DrawStyle.ELLIPSIS) {
public void paint(Graphics g) {
g.setColor(0x802d6e);
super.paint(g);
}
protected void layout(int width, int height) {
super.layout(width, height);
}
};
headertitle.setFont(fontnew);
gridbackManager = new VerticalFieldManager(VerticalFieldManager.NO_HORIZONTAL_SCROLL | VerticalFieldManager.VERTICAL_SCROLL) {
protected void paintBackground(Graphics graphics) {
graphics.drawBitmap(0, 0, backbitmap.getWidth(), backbitmap.getHeight(), backbitmap, 0, 0);
super.paintBackground(graphics);
}

protected void sublayout(int maxWidth, int maxHeight) {
int width = backbitmap.getWidth();
int height = backbitmap.getHeight();
super.sublayout(width, height);
layoutChild(_vfm, width, height);
setPositionChild(_vfm, 0, 0);
setExtent(width, height);
}
};
mainlayout = new VerticalFieldManager(VerticalFieldManager.NO_HORIZONTAL_SCROLL | VerticalFieldManager.VERTICAL_SCROLL) {
protected void paintBackground(Graphics graphics) {
graphics.drawBitmap(0, 0, backbitmap.getWidth(), backbitmap.getHeight(), backbitmap, 0, 0);
super.paintBackground(graphics);
}

protected void sublayout(int maxWidth, int maxHeight) {
int width = backbitmap.getWidth();
int height = backbitmap.getHeight();
super.sublayout(width, height);
layoutChild(backbittopfield, maxWidth, maxHeight);
setPositionChild(backbittopfield, 15, 10);
layoutChild(headertitle, maxWidth, maxHeight);
setPositionChild(headertitle, 25, 13);
layoutChild(gridbackManager, maxWidth, maxHeight);
setPositionChild(gridbackManager, 15, 33);
layoutChild(backbitbottomfield, maxWidth, maxHeight);
setPositionChild(backbitbottomfield, 15, 184);
setExtent(Display.getWidth(), Display.getHeight());
}
};
_vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Field.USE_ALL_HEIGHT | Field.USE_ALL_WIDTH) {

public void paint(Graphics g) {

super.paint(g);

}

protected boolean navigationMovement(int dx, int dy, int status, int time) {
this.invalidate();
return super.navigationMovement(dx, dy, status, time);
}

protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(292, 150);
layoutChild(listnew, maxWidth, maxHeight);
setPositionChild(listnew, 0, 0);

setExtent(292, 150);
}

};
listnew.setEmptyString(empty, 0);

_vfm.add(listnew);
mainlayout.setBackground(bg);
mainlayout.add(backbittopfield);
mainlayout.add(headertitle);
gridbackManager.add(_vfm);
mainlayout.add(gridbackManager);
mainlayout.add(backbitbottomfield);
add(headerbitmapfield);
add(mainlayout);

UiApplication.getUiApplication().getActiveScreen().invalidate();

Developer
Posts: 543
Registered: ‎12-23-2010
My Device: Z10
My Carrier: Airtel

Re: Listfield.invalidate() not working properly

I think you are using the following two lines to download images , right?

 

HTTPGetTask img = new HTTPGetTask(this, (String) hs.get("img"), bitmap, 30, 30);
img.go();

 

 

If so, dont write invalidate methods in the class which you sent.

 

in HTTPGetTaskImg.go() method after download the image write like this

UiApplication.getUiApplication().getActiveScreen().invalidate();

 

If above two lines are not to download image, you may wrote code for download image, use the above same line after downloading the image in image downloader function.

 

 

Thanks.

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Listfield.invalidate() not working properly

You have a lot of elements which are irrelevant to your current problem, some of them with a very wrong code.

For example:

- painting something in paintBackground then calling super.paintBackground is pointless - it will just paint over your bitmap unless super.paintBackground doesn't do anything (which I doubt)

- your sublayout() code, on the other hand, calls super.sublayout then starts tinkering with fields layouts and positions. In this case it is much safer to use Manager instead of VerticalFieldManager and drop the call to super.sublayot altogether.

 

The only code that is totally missing from what you've shown so far is the code dealing with ListField - drawListRow in particular. If you can show that and at least describe what HTTPGetTask does upon downloading the image, we will be able to help you better.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Trusted Contributor
Posts: 182
Registered: ‎09-22-2011
My Device: 9700
My Carrier: airtel

Re: Listfield.invalidate() not working properly

Thank you so much.It got fixed Smiley Happy