BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 01-29-2009, 07:03 AM   #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 SearchField

Please Login to Remove!

Hi,

I want to achieve similar logic as it is in the AddressBook for searching the contacts.
To do this i have written the code which is as follows,

AddressBook()
{
_addContact = new ADD();
_table =new Vector();


// setStatus(listField.getSearchBar())
// LabelField lbl = new LabelField("Address Book ".concat(navLabel), 0, -1, Field.FIELD_HCENTER
//);

listField = new ListField();
listField.setCallback(this);
//listField.setSearchable(true);

editField = new BasicEditField("Find: ", "")
{
public void paint(Graphics graphics) {

graphics.setBackgroundColor(0xCCFF66);
graphics.drawRect(0,15,35,1);
graphics.clear();
super.paint(graphics);
}

};
editField.setChangeListener(this);

add(editField);
add(listField);
reloadContactList();
}
public boolean onSavePrompt()
{
return true;
}
int sortIndex=0;
//String entry;
public void fieldChanged(Field field, int context)
{

if(field==editField)
{
String prefix = editField.getText();

for (int a=0; a<_table.size();a++)
{

Object obj= _table.elementAt(a);
if(obj instanceof String)
{
String entry =(String)obj;
if(entry.startsWith(prefix));
{
sortIndex=_table.indexOf(entry);
break;
//
}
}
}
int n=indexOfList(listField,"Mr",1);
Dialog.inform(" "+n);
listField.invalidate();
}
}


private boolean reloadContactList()
{
try {
blackBerryContactList =
(ContactList)PIM.getInstance().openPIMList

(PIM.CONTACT_LIST, PIM.READ_ONLY);

Enumeration allContacts = blackBerryContactList.items();
blackBerryContacts = enumToVector(allContacts);
listField.setSize(blackBerryContacts.size());

return true;
}
catch (PIMException e)
{
return false;
}
}

//Convert the list of contacts from an Enumeration to a Vector
private Vector enumToVector(Enumeration enum1) {
Vector v = new Vector();

if (enum1 == null)
return v;

while (enum1.hasMoreElements()) {
v.addElement(enum1.nextElement());
}

return v;
}
int move=0;
//ListFieldCallback methods
public void drawListRow(
ListField fieldVar,
Graphics graphics,
int index, int y, int width
){

if ( listField == fieldVar
&& index < blackBerryContacts.size())
{
blackBerryContact =
(BlackBerryContact)blackBerryContacts.elementAt(in dex);

String[] name = blackBerryContact.getStringArray(Contact.NAME, 0);


boolean found = false;

String nameseg;
String prefix;
String givenName;
String familyName;
StringBuffer sb = new StringBuffer();
if ((prefix = name[Contact.NAME_PREFIX]) != null) {
sb.append(prefix);

found = true;
}
if ((givenName = name[Contact.NAME_GIVEN]) != null) {
if (found) {
sb.append(' ');

}
sb.append(givenName);

found = true;
}
if ((familyName = name[Contact.NAME_FAMILY]) != null) {
if (found) {
sb.append(' ');
}
sb.append(familyName);


}
_table.insertElementAt(sb.toString(),move);
graphics.drawText(sb.toString(), 0, y, 0, width);
}
move++;
}

public Object get(ListField fieldVar, int index)
{
if (listField == fieldVar)
{
//If index is out of bounds an exception will be thrown,
//but that's the behaviour we want in that case.
return blackBerryContacts.elementAt(index);
}
return null;
}

public int getPreferredWidth(ListField fieldVar)
{
//use all the width of the current LCD
return Graphics.getScreenWidth();
}

public int indexOfList
(ListField fieldVar,String prefix,int start)
{
return listField.indexOfList(prefix, start);

}


But my ListOfIndex method doesn't work,it's returning -1 value.
How to resolve this problem,Is there something wrong in the above code.
Offline  
Old 01-29-2009, 07:06 AM   #2 (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

Any idea?
Offline  
Old 01-29-2009, 07:56 AM   #3 (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

Any idea?
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

JOHNSON CONTROLS NU-NCM300-1 METASYS NETWORK CONTROLLER GOOD CONDITION
$149.99
JOHNSON CONTROLS NU-NCM300-1 METASYS NETWORK CONTROLLER GOOD CONDITION pictureJohnson Controls MS-IOM2710-0U (NEW IN THE BOX)
$50.0
Johnson Controls MS-IOM2710-0U (NEW IN THE BOX) pictureNew Johnson Controls Actuator M9208-GGB-YK10 New Pull
$175.0
New Johnson Controls Actuator M9208-GGB-YK10 New Pull pictureSA23 JOHNSON CONTROLS LOW PRESSURE CONTROL RANGE 2/20
$24.99
SA23 JOHNSON CONTROLS LOW PRESSURE CONTROL RANGE 2/20 pictureT48 JOHNSON CONTROLS RETURN AIR SENSOR A91PAA-1C NIB
$29.99
T48 JOHNSON CONTROLS RETURN AIR SENSOR A91PAA-1C NIB picture






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