BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 03-20-2009, 03:11 AM   #1
jacytan
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: Globe
Posts: 52
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, 01:16 PM   #2
zechariahs
Thumbs Must Hurt
 
Join Date: Nov 2008
Location: Sioux Falls, SD
Model: 9530
PIN: N/A
Carrier: Verizon Wireless
Posts: 65
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-22-2009, 11:56 PM   #3
WonderfulRemote
Knows Where the Search Button Is
 
Join Date: Feb 2009
Model: 9000
PIN: N/A
Carrier: AT&T
Posts: 16
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, 03:42 PM   #4
squished18
Knows Where the Search Button Is
 
Join Date: Jan 2009
Model: 9700
PIN: N/A
Carrier: Rogers
Posts: 15
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, 08:21 PM   #5
jacytan
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: Globe
Posts: 52
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



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


US Stock 110VAC 60W 40KHz Ultrasonic Cleaning Transducer Cleaner & Driver Board picture

US Stock 110VAC 60W 40KHz Ultrasonic Cleaning Transducer Cleaner & Driver Board

$50.53



RDP Electronics Transducer Indicator E309 picture

RDP Electronics Transducer Indicator E309

$245.00



MTS LPRHVU00701 Temposonics Transducer Linear Position LPR-HVU-00701 90014868 picture

MTS LPRHVU00701 Temposonics Transducer Linear Position LPR-HVU-00701 90014868

$238.95



Psi-Tronix Motion Transducer Mod. 20 picture

Psi-Tronix Motion Transducer Mod. 20

$150.00



CR Magnetic CR4180-20 True RMS AC Current Transducer 3 Element - New picture

CR Magnetic CR4180-20 True RMS AC Current Transducer 3 Element - New

$229.95



NEW Novotechnik TLH-0750 TLH750 Position Transducer picture

NEW Novotechnik TLH-0750 TLH750 Position Transducer

$238.81







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