Question of ListField
Hello
I created a populatuing of a vector ListField.
The line draw well, but the next line line drawa just one image but not the rest of the text.
I checked vector and data receive very well to the (drawList).
any idea, what happens?
private class ListCallback implements ListFieldCallback { public void drawListRow(ListField list, Graphics g, int index, int y, int w) { /*// focuss color if(list.getSelectedIndex() == index) { g.setColor(0xffffff); g.fillRect(0,(index*list.getRowHeight()),list.getWidth(),list.getRowHeight()); g.setColor(0x000000); }*/ String RING="R:"; String SIZE="X:"; String LENGTH ="Y:"; String FLAVOR ="Z:"; Dummy item = (Dummy)_listElements.elementAt(index);// get the data to populate the Bitmap photo= Bitmap.getBitmapResource(item.getPhoto()); g.drawBitmap(10, y, photo.getWidth(),photo.getHeight(),photo, 0, 0);// draw the first photo int photoHeight = photo.getHeight(); y= photoHeight+10;// now y will be this Font regularFont = list.getFont(); // save the regular font for future use Font boldFont = regularFont.derive(Font.BOLD);// derive the bold font g.setFont(boldFont);// set our pen to bold for while g.drawText(item.getFullName(), 0, y, 0, w); g.setFont(regularFont);// back to norrmal pen int newY = y+ boldFont.getHeight();// get the new height to start drawing g.drawText(R+item.getR(), 0, newY+10, 0 , w); // draw the second line of text g.drawText(X+item.getX(),Font.getDefault().getAdvance(item.getR()+R)+10,newY+10,0,w); int newY2 = newY+regularFont.getHeight();// the third row draw staring point g.drawText(Y+item.getY(), 0, newY2+10, 0 , w); // draw the third line of text g.drawText(Z+item.getZ(),Font.getDefault().getAdvance(item.getY()+Y)+10,newY2+10,0,w);// third line right text // draw a line g.drawLine(0, y + list.getRowHeight() - 10, Display.getWidth(), y + list.getRowHeight() - 1); }
Hi peter,.
I found the error
y = photoHeight + 10; / / now there will be this
I changed on line t
int y1 y + photoHeight + 10; / / y1 will now be what
and following s all 'y' to 'y1 '.
Apart FRO
g.drawLine (0, y + list.getRowHeight () - 1, Display.getWidth (), y + list.getRowHeight () - 1); / / This remains the same, the value is 'y' not 'y1 '.
Now all the good ones: Angel
Thanks peter for your support, it was reallly help me to get my head around
Cheer
Tags: BlackBerry Developers
Similar Questions
-
question of ListField remove the last element
Hi all!
Is there a known problem in ListField which explains the revival of an OutOfboundException when removing an element from a list with a single element?
When you use listField.delete () I get this exception when the screen tries to set the focus.
Thank you for your response. I finally solved the problem in my case using the substitution of "isFocusable" you describe here.
While the default empty string is not the best solution for me display information when the list does not contain any element, I implemented the my own specific logic with a custom LabelField displayed instead of the ListField.
-
Hello
Can I have a ListField or table with text boxes and labels placed in each line of the list?
Help, please...
Thanks in advance...
Visit this link for the code example:
-
ListField background color / highlight
I am creating a ListField with a red background and white text at any time accept for when highlighted. When highlighted I would like to highlight to change to color pink (text remains black). In the following code, the background color is still red, however, the highlight is never fired.
Question = new ListField()
{Boolean _inFocus;
protected void onFocus (int direction)
{
super.onFocus (branch);
_inFocus = true;
Super.Invalidate ();
}protected void onUnfocus()
{
super.onUnfocus ();
_inFocus = false;
Super.Invalidate ();
}
public void paint (Graphics g)
{
g.setBackgroundColor (Color.RED);
g.setColor (Color.BLACK);
Super.Paint (g);If (_inFocus)
{
g.Clear ();
g.setBackgroundColor (Color.RED);
Super.Paint (g);
}
on the other
{
g.Clear ();
g.setBackgroundColor (Color.PINK;
Super.Paint (g);
}
g.setBackgroundColor (Color.PINK);
}
};If I remove the line g.setBackgroundColor (Color.RED); the work of highlighting (rose) and the text remains black, the background color of the listfield however goes to white. Am I miggins something logic here? Appreciate any comment. Thank you.
Kile
There is a great knowledge base article ListField coloring:
Study the code and be creative .
Good luck!
-
Hi, this is my first post, and I would like to ask a question about ListField.
How to make a listfield, who has similar function to ChoiceField: character presses will move to the first letter of the next item beginning with the character.
Thanks in advanc
for example:
Get the index of the first item with a certain letter as the first character in a hash table, with the first tank as the key.in keychar to check if there is an article for the tank in a hurry, take the 'b '.
the hashtable.get (b) method returns the index of 5.
Now you call setSelectedIndex on the listfield with the argument 5.I hope it's useful, most are basic java programming...
-
more UI questions. Custom LabelField and ListField text positioning
Hello
I have two questions.
1. I implement a LabelField, and I want to be the width of the screen and the text to be in the middle of its width. I am implemented with these bits of style: DrawStyle.HCENTER | DrawStyle.VCENTER | Field.FOCUSABLE | Field.FIELD_HCENTER. Then I overload layout() with this:
public void layout(int width, int height) { super.layout(width, height); setExtent(Display.getWidth(), this.getPreferredHeight()); }
The result is that the width of the field extends across the width of the screen, but the text is left-aligned. What I am doing wrong?
2. I've implemented a ListField personalized with a custom drawListRow(). For some reason, the color of the text in the highlighted line remains black. I don't know what I did wrong. I was expecting that there the default highlight a behavior, which is thoroughly blue, white text.
Thank you
public int moveFocus(int amount, int status, int time) { _listField.invalidate(getSelectedIndex()); return super.moveFocus(amount,status,time); } //Invoked when this field receives the focus. public void onFocus(int direction) { super.onFocus(direction); } //Invoked when a field loses the focus. public void onUnfocus() { super.onUnfocus(); _listField.invalidate(getSelectedIndex()); }
In my ListFields sexy do Paint (usually different color according to the status background), I use a substituted ListField that invalidates whenever he thinks he needs to, the idea being that it forces the line to be redrawn.
I'm not confident in them, but they do not seem to work. It's code that I created when I started it first, I didn't need to change so I don't have, but I'd be very confident that it is not optimal.
OK, so you know this code comes with no warranty.
I have replaced three routines as follows:
-
ListField highlighter in 5.0 OS question
Hello
I create a listfield to draw a menu screen. Each line has a picture and on highlightiing another picture needs to be shown.
I've commented the code in drawFocus () and drawListRow() I tried if (selectedindex == getcurrentIndex & listfield.isFocus) {image drawHighlighter}
another match tie without highlighter.
This code works perfectly in OS 6.0 Bt when I try in 5.0 that the hightlighter is not displayed.
Then I tried if (g.isDrawingStyleSet (Graphics.DRAWSTYLE_FOCUS)) uncommented super.drawFocus. Then the problwem is the blue highlighter is also illustrated with highlighter in the list. How to solve this problem. There is no work around for this?
This code should work:
If (SelectedIndex == listfieldgetSelectedIndex () & listfield.isFocus ())...
However, I think that I had problems with this part of the test:
listfield.isFocus)
and I ended up substituting onFocus and onUnfocus to set a flag tested myself.
Check so that two parts of your so, statement actually cause the drawListRow bypass the Highlighter and let us know.
-
Question about ellipsis in ListField
Hi all
I have a ListField with a custom reminder. My lines are ouptutted in the following format:
--------------------------------------------------------------
| Pic Pic right text left text |
--------------------------------------------------------------
I had available work without any problem. My problem is the following:
Sometimes, the value assigned to the 'left' text will be really long - if long as it hinders the space used by "Right text" and "Pic". In this case, I want to show an ellipse (using Graphics.ELLIPSIS in the drawText()). However, the points of suspension does not appear. I guess that's because it has not reached the end of the screen. Is it possible to put things up so that the selection button will appear once it hits the position of "right text"?
Thank you
You probably use the short version of drawText in your drawListRow. net.rim.device.api.ui.Graphics has several drawText methods - choose those with the width argument.
This could be what you need:
drawText(String aText, int aX, int aY, int aFlags, int aWidth)
Go DrawStyle.ELLIPSIS aFlags and width desired in aWidth.
-
ListField question - default update
When I view a listfield, how can I preset focus to a favorite item?
For example, I got 6 items in a list field, when the display, I would like to underline or put the current cursor on the 3rd.
Thank you.
LAN
ListField.setSelectedIndex (3)?
-
ListField with checkboxes associated example question
I use the code example...
in this perticular example I want to get the index of the selected how boxes can I do...?
Kaddy
getSelectedIndex returns only the index selected in the ListField, in this case, the ListField displays a special flag to indicate the selected items and this is what is needed.
Given that this "checkbox" display using the code user in the drawListRow routine, the field itself has no idea of which have been verified and who did not. Actually the same treatment that is used to detect if the box is checked should be used in the calling to detect program that have been checked.
In this example, the data to be displayed are from the _listData and are a series of objects ChecklistData. If the treatment must iterate over objects in listData, throw these ChecklistData objects and then use isChecked() against each object.
-
Hello
I want to draw several bitmap images on the same line of the ListField component. I wonder can I put Layout Manager in the ListField, because I don't want to define absolute coordinates.
This is my code:public void drawListRow(ListField list, Graphics g, int index, int y, int w) { if(index == 0) { g.drawText("Group 1", 0, 25, DrawStyle.ELLIPSIS, 70); g.drawBitmap(80, 0, 48, 48, Bitmap.getBitmapResource("red.png"), 0, 0); g.drawBitmap(170, 0, 48, 48, Bitmap.getBitmapResource("red.png"), 0, 0); g.drawBitmap(260, 0, 48, 48, Bitmap.getBitmapResource("red.png"), 0, 0); } else if(index == 1) { g.drawText("Group 2", 0, 75, DrawStyle.ELLIPSIS, 70); g.drawBitmap(80, 50, 48, 48, Bitmap.getBitmapResource("red.png"), 0, 0); g.drawBitmap(170, 50, 48, 48, Bitmap.getBitmapResource("red.png"), 0, 0); g.drawBitmap(260, 50, 48, 48, Bitmap.getBitmapResource("red.png"), 0, 0); } else if(index == 2) { g.drawText("Group 3", 0, 125, DrawStyle.ELLIPSIS, 70); g.drawBitmap(80, 100, 48, 48, Bitmap.getBitmapResource("red.png"), 0, 0); g.drawBitmap(170, 100, 48, 48, Bitmap.getBitmapResource("red.png"), 0, 0); g.drawBitmap(260, 100, 48, 48, Bitmap.getBitmapResource("red.png"), 0, 0); } }
Best regards.
Yes I did the same thing a long time back.
I did a ListFieldManager extends ListField. Then, inside of the done inside that class horizontalfields extends HorizontalManager.And Customize the SubLayout() of HorizontalFields and setPositionChild THE Bitmap field in SubLayout(). And add these instance BitmapField in HorizontalFields constructor.
I hope that you have some idea of Basic...
-
invokelater. You can also search the forums for it or google for inokelater + blackberry.
-
Touch anywhere on the screen calls the ListField TouchEvent.DOWN
Hello
I suffer with small complex issue. In the screen of my application, I have the title bar with a labelfield and two custom buttons.
Below the titlefield I add a list field.
Now, I have a few complex features on the field from the list. When I click each line in the list, it should move to another screen I do using navigation, click medium. Now if I touch the rank in the list (for touch devices), it should move to another screen. And if I touch along the line of the list, it will display popup menu (custom, not by default) with option of removal and details.
mListItem = new ListField(length, ButtonField.CONSUME_CLICK) { long touchedAt = -1; long HOLD_TIME = 500; // The regular getFieldAtLocation returns wrong values in open // spaces in // complex managers, so we override it // public int getFieldAtLocation(int x, int y) { // XYRect rect = new XYRect(); // int index = getFieldCount() - 1; // while (index >= 0) { // getField(index).getExtent(rect); // if (rect.contains(x, y)) // break; // --index; // } // return index; // } protected boolean navigationClick(int status, int time) { // Click related functionality return true; } protected boolean touchEvent(TouchEvent message) { if(message.getEvent() == TouchEvent.DOWN) { if (getFieldAtLocation(message.getX(1), message.getY(1)) == -1) { Logger.out("AccountList", "Touch down: getField location"); return true; // kill the event } else { touchedAt = System.currentTimeMillis(); touchedonList = true; Logger.out("AccountList", "Touch down: touched down "+touchedonList); } } else if(message.getEvent() == TouchEvent.UP ) { if(System.currentTimeMillis() - touchedAt < HOLD_TIME && touchedonList == true) { touchedAt = -1; // reset // Single Touch and Move to another screen } else if(touchedonList == true) { // Showing Menu Popup } } return true; // return super.touchEvent(message); // Not using this as it will show the default pop up }
And here's my reminder list field:
public class ListCallBack implements ListFieldCallback { public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width) { String strdomOrg = yyyyyyy; String text = xxxxxx; Font f = FONT_FAMILY_0_SF_AS_08; int h = f.getHeight(); // int height = (listField.getRowHeight() - h)/2 ; int height = h/2 ; y += height; graphics.setFont(f); graphics.setColor(Color.BLACK); graphics.drawText(strdomOrg, 10, y, DrawStyle.ELLIPSIS, width); y = y + h; graphics.setFont(FONT_FAMILY_1_SF_AS_08); graphics.setColor(Color.BLACK); graphics.drawText(text, 10, y, DrawStyle.ELLIPSIS , width); // use the offset instead int offset = (listField.getRowHeight() ) >> 1; if (index != 0) { graphics.drawLine(0, y - offset , width, y - offset); } } public Object get(ListField listField, int index) { // TODO Auto-generated method stub return mAccounts[index]; } public int getPreferredWidth(ListField listField) { // TODO Auto-generated method stub return screenWidth; } public int getPreferredHeight() { return getContentHeight(); } public int indexOfList(ListField listField, String prefix, int start) { // TODO Auto-generated method stub return listField.getSelectedIndex(); } }
Now the question is to come a different way:
1. whenever I touch the buttons in title field, he calls the listfield TouchEvent.DOWN. Then the click of a button does not work. Instead, by clicking on the title bar, it moves to another screen, which is the feature click list filed.
2. so I added the listfield at a value for money. :
m_vfmScreen = new VerticalFieldManager(VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR) { protected boolean touchEvent(TouchEvent message) { int event = message.getEvent(); if (event == TouchEvent.CLICK) { if (getFieldAtLocation(message.getX(1), message.getY(1)) == -1) return true; // kill the event else { } } return super.touchEvent(message); } // The regular getFieldAtLocation returns wrong values in open // spaces in // complex managers, so we override it public int getFieldAtLocation(int x, int y) { XYRect rect = new XYRect(); int index = getFieldCount() - 1; while (index >= 0) { getField(index).getExtent(rect); if (rect.contains(x, y)) break; --index; } return index; } };
While in the list key of field works. If I touch the buttons in the title bar, it does not. But if the keys become focus, this case they work.
So I am in dilemma, what exactly the problem. Can someone please help.
For me, there's a code unepxected in your touchEvent() - getFieldAtLocation(). If you want released supporess presses of field, I suggest you use code like this:
protected boolean touchEvent (TouchEvent message) {}
int x = message.getX (1);
int y = message.getY (1);
If (x < 0="" ||="" y=""> < 0="" ||="" x=""> getExtent () .width: y > getExtent () .height) {}
Outside the scope
Returns false;
} -
How do I know if an item is selected in a ListField? The documentation says that getSelectedIndex returns-1 if an item is not selected, but when I fill my list then check if on is selected, the following code always runs if the list contains elements.
If (editList.getSelectedIndex () >-1) {}
}
When I check the value of getSelectedIndex(), it is 0 if there is no selected item, or if the first element is selected and something greater than 0 if the other items are selected. So, what is a reliable way to only do something if an item is selected in the list.
also, really dumb question, how you define MultiSelect on a ListField? I wonder maybe if I need that goes out to make this work as I want to and the docs don't tell how to use the fields.
It seems that the documentation is confusing, as the ListField will return the index of the last selected element. Take a look at this thread - you can use 'getLeafFieldWithFocus()' to determine the currently selected field and if it is not centered, assumes that the index is - 1.
See this thread:
Problem with the ObjectListField
http://supportforums.BlackBerry.com/Rim/Board/message?board.ID=java_dev&message.ID=26369
You use MULTI_SELECT in the style of the constructor - see setting
Public ListField (int numRows, long style)...
-
The remote XML parsing and ListField implementation
I use Blackberry 9800 Simulator, JRE 6.0.0
Hello
I have a remote XML I want to analyze, but for some reason, my ListField shows only 1 row. I tried debugging and saw the number of attributes my vector, which is significantly greater than 1.
Here is my code: http://pastebin.com/zRDW2xfn
I'm doing something wrong?
In addition, in the ListFieldCallback, the drawListRow index does not increment...
Hey there,
I found the problem, if you print the exception, you will see what is wrong. Basically, you dodnt have access to the UI within this thread.
I changed the class connectionthread for you below.
private class Connection extends Thread{ public String title; public int i=0; public Connection(){ super(); } public void run(){ // define variables later used for parsing Document doc; StreamConnection conn; try{ conn = (StreamConnection)Connector.open("http://tpae.me/events.xml;deviceside=true"); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); docBuilder.isValidating(); doc = docBuilder.parse(conn.openInputStream()); doc.getDocumentElement().normalize(); NodeList list = doc.getElementsByTagName("Event"); for (i=0;i
Note: the fix is not optimal, but his show you how it should be done.
Please let me know if you still have problems or questions.
Maybe you are looking for
-
Hi, guys! My iphcone6 is icloud lock and now I can't use my phone, so how do I do?
-
OfficeJet 6210: Officejet 6210 do print after upgrade to 8.1 Windows
I've reluctantly Windows 8 upgraded to 8.1. And now, my Officejet 6210 not print. When you are prompted to print, the printer icon appears in the toolbar showing employment is printing, or, a message appears indicating printing, but nothing print
-
No sound on windows and YouTube, movies freeze.
Original title: no sound my sound worked very well and also my films all of a sudden I have no his and my movies freeze when I tried to also match youtubeI realized there is a red x on the sound icon and made troubleshooting who says driver not found
-
I can't connect to Windows Live Sync on my laptop. I have uninstalled/re-installed the program several times. This may be related to the problem 2 others have written about. I can access my desktop to online and check the files, but not my laptop.
-
Is there anyway to take a picture on the camera to my computer remotely?
I can take pictures near my computer built in camera, but I was wondering how to take a picture of me away since I have to use the mouse to click to take. Is there any kind of timer or a way to do this?