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
Developer
Posts: 93
Registered: ‎08-17-2009
My Device: Not Specified
Accepted Solution

Best way to detect list select event?

Hello,

 

I have a ListField where i get many list items. Whenever we select any list item, i want to detect immediately which row is selected with its data. What is the event to be perfect to achieve this? I tried, 'invokeAction', but didn't get detected when any list item is selected in listview.

 

Thanks.

Developer
Posts: 468
Registered: ‎08-07-2009
My Device: Curve, Bold, Storm
My Carrier: Blackberry Developer

Re: Best way to detect list select event?

hi,

 

 

list.getSelectedIndex();

----------------------------------------------------------
feel free to press the kudos button on the left side to thank the user that helped you.
please mark posts as solved if you found a solution.
Developer
Posts: 16,639
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Best way to detect list select event?

the listfield itself does not offer a trigger. i would suggest overwriting navigationmovement on the listfield, don't know if it is sufficient on touch devices though.

----------------------------------------------------------
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: 93
Registered: ‎08-17-2009
My Device: Not Specified

Re: Best way to detect list select event?

Hello, I want to know the event whis is getting triggered when any list item is selected. For ex: Under what event function do you  use getSelectedIndex() ?

Developer
Posts: 468
Registered: ‎08-07-2009
My Device: Curve, Bold, Storm
My Carrier: Blackberry Developer

Re: Best way to detect list select event?

hi,

 

 

    protected boolean navigationClick(int status, int time)
    {
        try
        {
            Field focus = UiApplication.getUiApplication().getActiveScreen().getLeafFieldWithFocus();
            if(focus == _list) 
            {
                SelectedIndex = _checkList.getSelectedIndex();
            }

        }
        catch(Exception e)
        {
            System.out.println("Exception:-  : navigationClick() "+e.toString());
        }
        return true;
    }

 

 

----------------------------------------------------------
feel free to press the kudos button on the left side to thank the user that helped you.
please mark posts as solved if you found a solution.
Developer
Posts: 19,623
Registered: ‎07-14-2008
My Device: Not Specified

Re: Best way to detect list select event?

[ Edited ]

I prefer this, and then adding a change listener to the ListField.  In the FieldChangeListener, you need to use 'getSelectedIndex'

 

public class ClickableListField extends ListField {

    protected boolean navigationClick(int status, int time) {
        this.fieldChangeNotify(3);
        return true;
    }

    protected boolean touchEvent(TouchEvent message) {
        // If click, process Field changed
        if ( message.getEvent() == TouchEvent.CLICK ) {
            this.fieldChangeNotify(3);
            return true;
        }
        return super.touchEvent(message);
    }

}

Developer
Posts: 16,639
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Best way to detect list select event?

it seems to be unclear what "selected" means in this context.

if you want the "user clicks on an item" event peter has the correct code.

if you want the "user selects the item without clicking" event you can check mine.

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