Image gone After Focusing

一笑奈何 提交于 2019-12-02 07:40:13
Nate

This is the second problem just like this I've seen in the last couple weeks.

Background

To understand the solution, first you should understand the basic UI classes in BlackBerry.

First, we have the Field class. A Field is the base class of the normal UI components. If you write a UI component yourself, from scratch, then you would subclass Field:

public class MyWidget extends Field {

However, if there already exists a BlackBerry class that does almost what you need, and you just need to change its behaviour a bit, then you would subclass something else. For example:

public class MyButtonWidget extends ButtonField {

The same pattern exists for the Manager class. If you are writing a Manager from scratch, then extend Manager:

public class MyManager extends Manager {

which involves doing this, according to the BlackBerry docs:

Implementing your own layout manager

If you have particular needs, you can implement your own manager. Extend the Manager class, and implement sublayout, getPreferredWidth, and getPreferredHeight. For efficiency, you may optionally override subpaint.

However, if an existing Manager subclass already does most of what you need, and you just want to customize it, then you might consider extending that subclass:

public class MyHorizontalManager extends HorizontalFieldManager {

In your case, your Custom_TopField is doing all of the required work for a fully custom Manager (see the highlighted quote above from the javadocs). So, there's not really any reason for you to extend HorizontalFieldManager. A HorizontalFieldManager is used when you just want to add() your fields, and have them all laid out horizontally. But, you do that explicitly in your sublayout() code. As it turns out, it looks like your logic is competing with the base class.

Solution

So, what you should do, is have your class just extend Manager:

public class Custom_TopField extends Manager implements FieldChangeListener {

If you do that, you will need to call a different super constructor. Something like this (you might want to pick different style constants depending on your needs):

Custom_TopField(final MainScreen mainscreen) {
   super(Manager.USE_ALL_WIDTH | Manager.NO_VERTICAL_SCROLL | Manager.NO_HORIZONTAL_SCROLL);

Another alternative would be to simply not implement sublayout(), extend HorizontalFieldManager like you originally had, and then control layout with the child fields' margins and long style flags. But, since the solution I gave above requires only changing 2 lines of code, that's probably the easiest for you this time.

Other Problem(s)

I also noticed in your code, and screenshots, that the Download button doesn't show up. I don't know the exact size of all your png images, but if the refresh and download images are the same size, then your current logic is just laying out the refresh button right over the download button. So, the download button is hidden. That's probably not what you want?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!