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


Brand New STMicroelectronics M4T28-BR12SH1 TIMEKEEPER SNAPHAT Battery picture

Brand New STMicroelectronics M4T28-BR12SH1 TIMEKEEPER SNAPHAT Battery

$16.49



50 Pcs S8050 General Purpose NPN Transistor TO-92 40V 800ma 100Mhz USA Shipping picture

50 Pcs S8050 General Purpose NPN Transistor TO-92 40V 800ma 100Mhz USA Shipping

$4.89



BLF188XR RF Power LDMOS Transistor High Frequency Microwave Tube picture

BLF188XR RF Power LDMOS Transistor High Frequency Microwave Tube

$118.56



2pcs  POWER PACK chip STK0080 STK-0080 picture

2pcs POWER PACK chip STK0080 STK-0080

$28.64



TO-92 Assortment NPN PNP DIY kit 15 value 600pcs Transistor  picture

TO-92 Assortment NPN PNP DIY kit 15 value 600pcs Transistor

$11.52



MOSFET - IRF540N 100V 33A - Transistor for Arduino Pi TT picture

MOSFET - IRF540N 100V 33A - Transistor for Arduino Pi TT

$49.72







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