07-16-2009 04:51 AM - edited 07-16-2009 06:27 AM
This is an expansion of a discussion found on (Problem in Customizing KeywordFilterField) which was mistakenly marked as solved without explanation of the implementation.
This is what I need:
A list field to behave much the same as Phone application's (actually: phone log and address book) call/contact list.
What I mean is: press the green key on your home screen.
A list is shown with phone log items (call status, duration, etc.)
But when you start typing a different list is being displayed: an address book list with filtered results in it.
OK, you say: "where is the problem, those are just list fields". But the special thing is the fact that when you scroll on one of the filtered items, another row appears in the list which displays the number (one or more, depending on the count of the numbers for selected contact).
I was able to mimic this behavior by inserting additional rows, but the problem is how to remove them.
What I did is something like this:
public void drawListRow(ListField list, Graphics g, int index, int yPosition, int width)
if (list.getSelectedIndex() == index)
focused = true;
if(focused && !(INSIDE_INSERTED_INDEX_RANGE))
insert(" insertion 1", index + 1);
for (int i = 0; i < fNumberOfInsertedRows; i++)
erase(insertionsCameAfterThisIndex + 1);
// finally draw the text
String text = getPhoneItemByIndex(index).getName();
g.drawText(text, 0, yPosition, 0, width);
The code is a simlification of the problem.
The insert and erase methods also take care of ListField.setSize()
The part with the removing code does remove the rows but unfortunately, the 0th row gets the focus. And using
ListField.setFocus() ListField.setSelectedIndex() overwhelmes the stack
How can I dynamically remove a row from a listField and set the focus on a chosen row ?
Do I need to extend the listField and override the Paint() method or is this callback implementation enough ?
Thanks for reading this
07-16-2009 05:17 AM
07-16-2009 06:26 AM
You have just stumbled upon a 'typo'.
My previous post has an error:
"And using ListField.setFocus() overwhelmes the stack"
Should have been written as:
"And using ListField.setSelectedIndex() overwhelmes the stack"
The interesting thing is that there is no recursion as one might think.
No entry to the drawListRo() has been made in between the call to the setSelectedIndex() and the exception thrown.
So I wonder, if maybe I am using a completely missed approach here.