BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 01-31-2009, 12:29 PM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: AT
Posts: 81
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 12:16 AM   #2 (permalink)
New Member
 
Join Date: Feb 2009
Model: 8700
PIN: N/A
Carrier: Vodafone
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

can u elaborate on what is the expected output and actual output in the code above
Offline  
Old 02-17-2009, 06:57 AM   #3 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
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 06:59 AM.
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.