BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 03-20-2009, 04:11 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: Globe
Posts: 52
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with ObjectListField

Please Login to Remove!

Hello,

I am having trouble with the getSelectedIndex() method of ObjectListField.
Supposedly, when there is no selected index, it returns -1. But how come it always returns the index of the last item?

To demonstrate, i created my own dialog that has a similar functionality to the "Select Device Dialog" of the Bluetooth application in BB. I have an ObjectListField and a Cancel Button. What i simply did is change the label of the button to show the selected index. I have attached my sample code below.

Code:
public class MyDialog extends Dialog
{       
        private ObjectListField m_list;
        private ButtonField m_btn;      

        public MyDialog ()
        {
                super("Select Device:",null,null,0,Bitmap.getBitmapResource("bluetoothIcon.PNG"),Manager.FOCUSABLE);

                m_list = new ObjectListField();
                m_btn = new ButtonField("Cancel",Field.FIELD_HCENTER);
                m_list.set(new String[]{"first","second"});

                add(m_list);
                add(m_btn);
        }

    protected boolean navigationClick(int status, int time)
    {   
        m_btn.setLabel(Integer.toString(m_list.getSelectedIndex()));

        return true;
    }
}
Can somebody help me on this problem? Is there something wrong with my code or is the API buggy? All i want to happen is to return a -1 index if there is no item selected in the list.

Also, I have tried the isFocus() method using it to check if the list is being focused, it always returns false eventhough the list is OBVIOUSLY being focused. I have run out of options on how to determine the solution to this problem. please help!

Thanks a lot.
Offline  
Old 03-22-2009, 02:16 PM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Nov 2008
Location: Sioux Falls, SD
Model: 9530
PIN: N/A
Carrier: Verizon Wireless
Posts: 65
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

This may seem like a stupid question - Is it possible that you're checking the values in the list to see what is there and accidentally selecting an item?
__________________
Handspring >> Palm >> BB Pearl >> BB Storm

Tumblog: http://www.geekkink.com
Blog: http://www.zechariahs.org/blog
Offline  
Old 03-23-2009, 12:56 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Feb 2009
Model: 9000
PIN: N/A
Carrier: AT&T
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are you by any chance scrolling down past the bottom of the list to select & click the button?
Or are you invoking getSelectedIndex when the screen is no longer on top?
I use getSelectedIndex in several apps and confirm that it works perfectly on every simulator & device that I've tested on (from 4.2 up).
Offline  
Old 08-11-2009, 04:42 PM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Jan 2009
Model: 9700
PIN: N/A
Carrier: Rogers
Posts: 15
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi jacytan,

Did you ever get this resolved? I'm running into the same problem with some code I'm working on now.

Thanks,
squished18
Offline  
Old 08-12-2009, 09:21 PM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: Globe
Posts: 52
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi squished18,

Here is what i did.

Code:
    
protected boolean navigationClick(int status, int time)
{   
     if(this.getLeafFieldWithFocus() == m_list)
     {
        m_btn.setLabel(Integer.toString(m_list.getSelectedIndex()));

        return true;
     }
     return false;
}
Do you get it?
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.