Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

adding and removing listField items dynamically

[ Edited ]

Hi all.

 

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))
{
...

if(shouldCreate)

{

  insert(" insertion 1", index + 1);

fNumberOfInsertedRows++;

}

else

{

for (int i = 0; i < fNumberOfInsertedRows; i++)
{
erase(insertionsCameAfterThisIndex + 1);

fNumberOfInsertedRows--;

}

}

...
}

// 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 Smiley Sad

 

In short:

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 Smiley Happy

 

Myraddin

 

Message Edited by myraddin on 07-16-2009 12:27 PM


"Listen carefully, I shall say this only once"
Developer
Posts: 16,999
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: adding and removing listField items dynamically

you can use setSelectedIndex on the ListField.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: adding and removing listField items dynamically

Sorry.

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.



"Listen carefully, I shall say this only once"