How to use ListField Class to display rows of text? - blackberry

Plz help me in cited to above mentioned tropic
The row should contain
row1 text text img
text text
row2 text text img
text text
Every row should look like that. Actually it is going to display multiple extracted JSON data in rows.

Just call list.setRowHeight() to give yourself enough room to display all of this, and then in your ListFieldCallback's drawListRow() method, paint each Field how you'd like. If you need further explanation post a comment and I can expand.
Edit for comments:
You can do something like this in drawListRow()
public void drawListRow(Graphics graphics, int index, int y, int width) {
//get your strings from the vector, I'm calling them t1 and t2 and the image img
//draw the top line of text
graphics.drawText(t1, 0, y);
//draw the second line of text
graphics.drawText(t1, 0, y + getFont().getHeight()); //You can cache the font height for performance if you want
//draw the bitmap
graphics.drawText(width - img.getWidth(), y, img, 0, 0);
}

Related

Remove spacing between the first row and second row in the Gridlayout

Thank you very much for your help in advance.
Let me explain the problem,
I have grid layout where I am adding the labels in the first row (its called header row). In the next 5 rows, I am adding text field, combo and date fields.
The problem I am facing is, I would like to remove the space between header(first) row and second row and continue to have default space from second row to the last rows. I have highlighted the space as red line in the snapshot
Please find the snapshot in attachment.
Any hints, please advise.
As I've mentioned in the comments, position of a component in a GridLayout defined by a top value in css. So you would need to change it if you want to re-position(remove space, in this case) an element. The problem here is that
GridLayout not necessary starts from top, so you would need to figure out a correct value for a top,
and then you would need to differentiate a correct component(label in this case) using :n-th child, since a class name applied to a component, is not propagated to a parent's v-gridlayout-slot.
As for an alternative, you could add a common styleName to all components (except labels) and using this style set margins(left, right, bottom)to all the components. (In the example below used a pink color to verify styles are applied.)
In this scenario, output is like this:
The css part:
.addPadding{
margin-bottom: 15px;
margin-left: 15px;
margin-right: 15px;
background-color: pink;
}
Code used:
setContent(addGridLayout())
////
private GridLayout addGridLayout(){
// Create a 4 by 4 grid layout.
GridLayout grid = new GridLayout(4, 4);
//grid.setSpacing(true);
grid.addStyleName("example-gridlayout");
// Fill out the first row using the cursor.
for (int i = 0; i < 4; i++) {
Label l=new Label("Col " +
(grid.getCursorX() + 1));
grid.addComponent(l);
grid.setComponentAlignment(l,Alignment.BOTTOM_CENTER);
}
// Fill out the first column using coordinates.
for (int i = 1; i < 4; i++) {
TextField x=new TextField();
x.addStyleName("addPadding");
grid.addComponent(x, 0, i);
}
// Fill out the secondcolumn using coordinates.
for (int i = 1; i < 4; i++) {
TextField x=new TextField();
x.addStyleName("addPadding");
grid.addComponent(x, 1, i);
}
// Fill out the third column using coordinates.
for (int i = 1; i < 4; i++) {
DateField x=new DateField();
x.addStyleName("addPadding");
grid.addComponent(x, 2, i);
}
// Fill out the third column using coordinates.
for (int i = 1; i < 4; i++) {
ComboBox x=new ComboBox<String>();
x.addStyleName("addPadding");
grid.addComponent(x, 3, i);
}
return grid;
}
if the columns have fixed width you could create 2 GridLayouts one for the header and one for the content. Both of them should have no margin and the layout that contains them should have no spacing.

customized editable text field with predefined width and height

i am developing a mobile app in blackberry 7,i need to create a editable text field as shown in below figure with save and clear button.initially it has to show customized edittext field with predefined width(fixed as it should not exceed the defined layout) and height,and automatically get appended by new line if user requires to enter more characters after reaching predefined space as user keeps filling the field.
i googled, but i did not get any source which is similar to this.please help me by providing any suggestion or with samples
Blackberry fields decide their size in their layout field. I'm not entirely sure what EditField does in its layout, but I was able to get the behaviour you want by setting the extent. Every time the edit field text will wrap, layout will be triggered so that it can grow.
EditField editField = new EditField()
{
private final int MIN_HEIGHT = 200;
protected void layout(int width, int height)
{
super.layout(width, height);
if (getHeight() < MIN_HEIGHT)
{
setExtent(getWidth(), MIN_HEIGHT);
}
}
};
editField.setBorder(BorderFactory.createSimpleBorder(new XYEdges(1, 1, 1, 1)));
add(editField);

How to Increase the row height of the selected item of listfield

I am using a ListField for my app to show the data in a list. Now my requirement is that i want to increase the row height of the selected item of the list.
For this, i created a GridFieldManager and populated my list using this manager. I then override the onFocus() method of this manager. But, this method is never invoked. As a result i am unable to increase the height of the selected row item.
Please help.
ListField rows are all designed to be uniformly sized, so unfortunately you won't be able to directly change the size of one row. It's possible you can emulate it by setting it so that the row above and below draw a little bit of the focus color at the bottom and top respectively. Alternatively, you could have one field that just stays centered above whatever row is focused. Then redraw this "floating Field" with the information from the selected row.
I got it working. I faked the ListField implementation. I removed ListField and replaced it with VerticalFieldManager. I adjusted its size during onfocus() and onUnfocus() and used sublayout() to change the height of this manager. Its working exactly the way i want.
you can increase the row height/font text/...
as ultimately, all of the api's call canvas's paint methods
how to do:
//try playing with the font_type,font height
Font myFont = Font.getDefault().derive(Font.PLAIN, 14, Ui.UNITS_px);
private class ListCallback implements ListFieldCallback {
public void drawListRow(ListField list, Graphics g, int index, int y, int w) {
g.setFont(myFont);
String text = (String)listElements.elementAt(index);
g.drawText(text, 0, y, 0, w);
//you can increase the height of a particular row in the height parameter.
// if you want it to be specific, put an 'if conditon'
EX: if(index=1)
{
w+=10;
}
}
}

Delphi: How to draw some text in requested width and number of lines, with ending ellipsis?

I need to draw some text in a table cell with fixed width (in pixels) and fixed number of text lines. If the text is clipped by cell rectangle, it must end with ellipsis. The problem is I can't calculate the text rectangle correctly (or the TextRect/DrawText procedure isn't working correctly, I'm not sure).
I tried to use this method of calculating text rectangle:
var
TextRect: TRect;
tm: TEXTMETRIC;
...
GetTextMetrics(Canvas.Handle, tm);
TextLineHeight := tm.tmHeight + tm.tmExternalLeading;
TextRect.Bottom := TextRect.Top + TextLineHeight * NumberOfLines;
Canvas.TextRect(TextRect, 'some long long long text',
[tfTop, tfLeft, tfEndEllipsis, tfWordBreak]);
The clipping rectangle has been calculated correctly, but the ellipsis isn't appearing.
Ellipsis appearing when I decrease the height of clipping rectangle by 1 pixel:
TextRect.Bottom := TextRect.Top + TextLineHeight * NumberOfLines - 1;
But some pixels of the bottom line of my text are clipped then.
How to do it correctly?
Since the api puts the end-ellipsis only when the last line does not fit in the specified rectangle, one workaround could be to specify tfModifyStringin formatting options in a first call to 'TextRect' with a rectangle with reduced height, then call 'TextRect' again with a proper sized rectangle and the modified text:
var
Text: string;
...
Text := 'some long long long text';
SetLength(Text, Length(Text) + 4); // as per DrawTextEx documentation
Dec(TextRect.Bottom);
Canvas.TextRect(TextRect, Text,
[tfTop, tfLeft, tfEndEllipsis, tfWordBreak, tfModifyString]);
Inc(TextRect.Bottom);
Canvas.TextRect(TextRect, Text, [tfTop, tfLeft, tfWordBreak]);
I'd be keeping an eye though, in case a future version of the OS decides to clip the last line entirely if it doesn't entirely fit in the rectangle.. :)
I'd try calculating the needed rectangle via Canvas.TextRect(..., [tfCalcRect, ...]).

How can I show a textbox on my BlackBerry application?

How can I add a textbox so a user can enter numeric values into my form? I need the borders of the textbox control to be visible at all time.
Thanks.
You should implement your own class, inherited from TextBox and override void paint(Graphics g) method.
Smth, like that, sorry i write from mobile:
public void paint(Graphics g)
{
// set color
g.setColor(0x555555);
// draw 100*100 rectangle
g.drawRect(0, 0, 100, 100);
// dont forget to invoke
super.paint(g);
}
If you dont want use overriding,
In OS 4.6+ you can use Border and BorderFactory classes (search in All Classes list).
// Each integer represents the amount of space between the box and border
// The four parameters of an XYEdge object represents each edge,
XYEdges thickPadding = new XYEdges(10, 10, 10, 10);
// Sample text field with a thick and solid rounded border
// and single solid colour background.
RichTextField simpleField = new RichTextField("Solid rounded border, solid background");
// Create border and background objects
Border roundedBorder = BorderFactory.createRoundedBorder(thickPadding, Border.STYLE_SOLID);
// Set the objects for use
simpleField.setBorder(roundedBorder);
// Add the field to the screen
add(simpleField);

Resources