BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 01-31-2009, 01:29 PM   #1
taqi.mir
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: AT
Posts: 81
Default Is something wrong in this code?

Please Login to Remove!

Hi,

I am having trouble in tracing the string from vector there by selecting the row in the ListField.Please see below listed code

public int indexOfList
(ListField fieldVar,String prefix,int start)
{
boolean bolResult;
String entry;
for (int a=0; a<_table.size();a++)
{
Object obj= _table.elementAt(a);
if(obj instanceof String)
{
entry =(String)obj;
bolResult = entry.startsWith(prefix);
Dialog.inform(""+bolResult+" "+prefix+" "+entry);
if(bolResult==true)
{
Dialog.inform("equal");
//Dialog.inform(""+bolResult);
searchIndex=_table.indexOf(entry);
listField.setSelectedIndex(searchIndex);
listField.setFocus();
break;
}
else
{
//Dialog.inform(""+bolResult);
}

}
}
return searchIndex;
}


Am i doing wrong something?
Offline  
Old 02-17-2009, 01:16 AM   #2
SunitK
New Member
 
Join Date: Feb 2009
Model: 8700
PIN: N/A
Carrier: Vodafone
Posts: 7
Default

can u elaborate on what is the expected output and actual output in the code above
Offline  
Old 02-17-2009, 07:57 AM   #3
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default

And to start with, if you really want help with code you should first read this thread which is stuck at the top of the forum. That way we could look at your code like this:
Code:
public int indexOfList (ListField fieldVar,String prefix,int start)
{
  boolean bolResult;
  String entry;
  for (int a=0; a<_table.size();a++)
  {
    Object obj= _table.elementAt(a);
    if(obj instanceof String)
    {
      entry =(String)obj;
      bolResult = entry.startsWith(prefix);
      Dialog.inform(""+bolResult+" "+prefix+" "+entry);
      if(bolResult==true)
      {
        Dialog.inform("equal");
        //Dialog.inform(""+bolResult);
        searchIndex=_table.indexOf(entry);
        listField.setSelectedIndex(searchIndex);
        listField.setFocus();
        break;
      }
      else
      {
         //Dialog.inform(""+bolResult);
      }

    }
  }
  return searchIndex;
}
I assume you are trying to implement ListFieldCallback.indexOfList. If true your implementation does not really match the contract specified by the API documentation. You probably don't really want to be popping up Dialogs in that method either as it could quickly get messy. If you want to provide debugging output I would recommend System.out.println()

In any case: the search is supposed to start at start, not 0; if a match is not found it should return fieldVar.getSelectedIndex(); or if the search is not appropriate in context return -1.

If you don't pop up modal dialogs, you can probably dispense with the call to setFocus() which should likely be called on a defined variable, fieldVar? Or is listField (and searchIndex for that matter) defined elsewhere? This may go for the call to setSelectedIndex as well, but as SunitK said, what are you trying to do?

Last edited by hrbuckley; 02-17-2009 at 07:59 AM..
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


Dec/Adac Corp. D4-10390 Rev 6 Model 1664ATTL Output Pulse Board 1983 (B16) picture

Dec/Adac Corp. D4-10390 Rev 6 Model 1664ATTL Output Pulse Board 1983 (B16)

$189.99



Original New DEC Digital DCJ11-AE 57-19400-09 Vintage CPU x 1pc picture

Original New DEC Digital DCJ11-AE 57-19400-09 Vintage CPU x 1pc

$100.00



Vintage DEC PDP11 Option Bulletin MSV11-L Memory Module 1981 picture

Vintage DEC PDP11 Option Bulletin MSV11-L Memory Module 1981

$2.95



Armco Policies Dec 1965 Steel Plant Vintage 26 pgs booklet Butler, Pa 29th print picture

Armco Policies Dec 1965 Steel Plant Vintage 26 pgs booklet Butler, Pa 29th print

$7.49



VINTAGE Bruker Board DEC W4P3042 for SpectroSpin 250 picture

VINTAGE Bruker Board DEC W4P3042 for SpectroSpin 250

$50.00



Niedermaier vintage Mannequins Visual Display Props Dec. 1991 Catalogue picture

Niedermaier vintage Mannequins Visual Display Props Dec. 1991 Catalogue

$141.00







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