How to create fields having multiple attributes(each Field containing multiline texts,image icon,date etc) in an Application.??
What exactly they are called as???
In the BlackBerry Java UI framework, the fundamental class is a Field. A Field might be a TextField or BitmapField or ButtonField.
Managers
If you want to create a field that is a group of fields, you would normally use or create a class that extends Manager. A Manager is a container of field objects, that is responsible for properly laying out (sizing and positioning) the fields it contains.
Also, a Manager is itself a Field in that it extends Field. So, you can have a heirarchy of field objects, and managers. A Manager can contain child Manager objects, which themselves contain low-level fields: buttons, labels, sliders, etc.
You can extend the Manager class yourself, and implement the methods to properly size and layout its children,
protected abstract void sublayout(int width, int height);
public int getPreferredWidth();
public int getPreferredHeight();
or you can use one of the pre-written RIM managers, like VerticalFieldManager, or HoriztonalFieldManager.
VerticalFieldManager, for example, lays out all Field objects that you add() to it, in order, vertically from top to bottom. You can adjust spacing on the child fields by calling setMargin() on each field.
Some other built-in Manager subclasses:
HorizontalFieldManager - lays out child fields horizontally, in the order added, from left to right
FlowFieldManager - lays out child fields horizontally, until horizontal space is full, and then vertically (like the words on a page flow)
AbsoluteFieldManager - lays out child fields at fixed (x,y) screen coordinates
GridFieldManager - lays out child fields in a grid of rows and columns ... like a table
Related
I am looking into sub-classing a container component to act as a "listbox" container of sub-classed TPanels that are acting as "listitem" members. Basically, my CustomListItems are TPanels that contain some images, labels, and/or other controls. These CustomListItems will be created dynamically and will have dynamic sizes. Their widths shall be equal to that of their parent container, but their heights might differ.
I want my container "listbox" to mostly behave like a standard TListBox, in that it shall be vertically SCROLLABLE, and that the added items shall be stacked on top of each other in the most automatic way possible. For example, doing:
CustomListItem* myCustomListItem = new CustomListItem(this, param1, param2, param3); // this = TOwner
myCustomListItem->Parent = myCustomListBox;
will automatically position the added child TPanel item in the first vacant slot of its CustomListBox container.
What I am seeking is the most standard way for implementing this parent/child, container/contained relationship. I am unsure what container component to sub-class and how to go about this. I am considering two approaches:
Possibly using a TLayout, TGridLayout, or TGridPanelLayout container if it is vertically scrollable and if it will handle rendering/positioning the added child TPanels (my CustomListItems) automatically.
If there is no "easy" or "standard" way to implement the above behavior, I would maybe consider using a plain TVertScrollBox as the "listbox" container, and then custom-handle the positioning and repositioning of the added items "manually".
For the latter approach, what I need is information about which events might trigger the insertion and removal of child items, and how to handle those events properly. For example, I would keep track of added items and their positions relative to the parent container. When new items are inserted, I can then manually handle positioning them correctly in the container. I can do that "internally" by overriding/overloading (not sure) the AddObject method, but I would still need to handle certain events for "external" insertion/removal of objects (e.g: myCustomListItem->Parent = myCustomListBox;)
I hope I made my question clear enough. Any help would be highly appreciated.
My application is similar to Vaadin Dashboard Demo (please click login after you visit this link). So all my mini dashboard items are wrapped around an abstract component that is of height 300px. One of those items is a Grid wrapped around this 300px height abstract component.
My customer hates it when he sees a large column and .v-grid-cell cuts his cell off:
text-overflow: ellipsis;
So in the #PostConstruct of my Vaadin Grid(and everywhere I mess with the container) i have
this.recalculateColumnWidths();
to alleviate my customer's concern. I tell him he can resize the column but he is not satisfied.
When my container size is small, most of the rows are visible and hence the column widths are perfect. When i have a lot of rows i have to scroll. The column widths are calculated based on the set of initially visible rows. When i scroll down, and if a newly visible row has a large column then the column gets cut off.
I can alleviate my problem by using HeightMode.ROW and make the parent Component a scrolling Panel like:
panel.setWidth("100%");
panel.setHeight("310px");
But I have a lot of action going on my Grid's FooterRow and so i don't want my user to have to scroll to the bottom to see the footers if row size is say 100. As a result my Grid has default HeightMode -> HeightMode.CSS. I like it. It always shows my HeaderRow and FooterRow and scrolls only the rows section of my Grid.
What have i tried:
Give each column humongous size or expand ratio. Customer rejected it.
I tried adding a listener for scroll event unsuccessfully. I used this similar question mentions. I could not get the scroll listener turned on.
ScrollingGrid.java:
public class ScrollingGrid extends Grid{
List<ScrollingGridScrollListener> listeners = new ArrayList<ScrollingGridScrollListener>();
private void fireSrollEvent() {
for (ScrollingGridScrollListener listener : listeners) {
listener.doGridScroll();
}
}
public void addScrollListener(ScrollingGridScrollListener listener) {
listeners.add(listener);
}
#Override
public void beforeClientResponse(boolean initial) {
super.beforeClientResponse(initial);
fireSrollEvent();
}
}`
ScrollingGridScrollListener.java:
public interface ScrollingGridScrollListener {
public void doGridScroll();
}
and in my Grid:
addScrollListener(this);
and
#Override
public void doGridScroll() {
Notification.show("You are scrolling!\nYou can add your own behavior here!");
this.recalculateColumnWidths();
}
I see the notification when page loads. Maybe i should not override beforeClientResponse method in Grid. But I don't know what method to override to achieve a scroll listener.
Help me figure out this scroll listener or if there is another way i can get recalculated column widths on scroll, please let me know.
Thanks for reading this very long question.
Version: 7.6.8
I searched how to set header and footer in BlackBerry and I found the functions setTitle() and setStatus().
My problem is I have created a class that extends VerticalFieldManager. In VerticalFieldManager, it is not showing me setStatus function as this is function of MainScreen class.
You're right. A VerticalFieldManager does not allow you to setStatus() directly.
It's important to understand the relationship between the classes in the BlackBerry UI framework.
First of all, there are Screen classes. Normally, a Screen will take up the entire device screen. You can have many different Screen classes in your app. Maybe one Screen for a splash image, one screen for a map view, one screen for settings, etc.
Inside your screens, you will often have Manager classes. A VerticalFieldManager is a kind of Manager that arranges its contents top-to-bottom, in the order that you add them. A Manager holds a group of related objects, but it does not have to span the full screen height, or width.
Inside your managers, you will usually have multiple Field objects. A Field is the individual item in the heirarchy. ButtonField, EditField, or BrowserField are all kinds of fields. They will usually be added to managers (containers). Those managers will then usually be added to screens.
So, in your case, I think what you should have is a screen class. In that screen class, you will set the header and footer by calling setTitle() and setStatus(). The content between the header and footer will all be contained in a VerticalFieldManager that you add to the screen. Something like this:
public class MyScreen extends MainScreen {
public MyScreen() {
super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
// set a header for this screen
setTitle("My Header / Title");
// screen contents go in the vertical field manager
// NOTE: you can replace VerticalFieldManager with your own class
// that extends Manager, or VerticalFieldManager, if you like
VerticalFieldManager vfm = new VerticalFieldManager();
vfm.add(new LabelField("One"));
vfm.add(new ButtonField("Two", ButtonField.CONSUME_CLICK));
vfm.add(new CheckboxField("Three", true));
add(vfm);
// use a bitmap as a footer
Bitmap footer = Bitmap.getBitmapResource("footer.png");
setStatus(new BitmapField(footer));
}
}
How to add eyelid field manager to grid field manager.
I have created a grid layout.Now i want to add an eyelid field manager on top of it.
I have been able to add both of them separately but now am unable to use them together.
Following code was used when i wanted to integrate
_eyelidFieldManager.add(grid);
add(_eyelidFieldManager);
How else can this be accomplished?
I have also tried adding this way
grid.add(_eyelidFieldManager);
add(grid);
But what what i get is the eye lid field manager comes below the grid.I want to superimpose the eyelid on top of grid.So that when i click anywhere on the screen of grid,the eyelid opens.Your help will be appreciated.
EyelidFieldManager has three main methods for adding fields:
addTop(Field f): adds a field to the top eyelid.
addBottom(Field f): adds a field to the bottom eyelid.
add(Field f, int x, int y): adds a field and places it in the specified absolute position. Fields added using this method will remain visible after the lids get closed.
As you can see, EyelidFieldManager extends from AbsoluteFieldManager and this is what makes this class so problematic, as fields added in between the lids must be layed out using absolute coordinates.
In turn, AbsoluteFieldManager extends Manager so it has an additional add(Field f) method, which is overriden to add the field to the bottom eyelid. This is what is happening in your case. You should instead use the third add method listed above and provide absolute coordinates.
I'm trying to set the padding between various fields in a blackberry app. I can use setpadding method but this seems like overkill for what im trying to achieve. I just want to set a consistent spacing around all fields. Is this possbible without using setpadding? My fields are part of a verticalfield managers if that helps.
Thanks
If these are Fields you will be using frequently with the same amount of spacing the easiest solution would probably to extend the Field and in the constructor call a setMargin() on it.
public class SpacedLabelField extends LabelField {
public SpacedLabelField(String text, long style) {
super(text, style);
setMargin(10, 10, 10, 10);
}
}
I would recommend setMargin() because the Managers will take that information and give you an even spacing. For example, you have Field A with a bottom margin of 10 and Field B with a top margin of 10. If you stack A on top of B you will end up with a spacing between them of 10 rather than 20 (at least this has been my observed behavior in 5.0).
At any rate, now rather than having to create your Field and then call setMargin() on each, you only have to call your class and it will already be formatted for you.
Alternatively you could create your own Manager and in the sublayout() call implement a spacing between the Field when you are laying out and positioning them.