BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 01-29-2009, 07:03 AM   #1
taqi.mir
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: AT
Posts: 81
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
taqi.mir
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: AT
Posts: 81
Default

Any idea?
Offline  
Old 01-29-2009, 07:56 AM   #3
taqi.mir
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: AT
Posts: 81
Default

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



DEC DIGITAL VINTAGE RA8X Control Panel picture

DEC DIGITAL VINTAGE RA8X Control Panel

$30.00



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 Journal Beautiful Garden Flower Embossed Leather-Antique Handmade Dec... picture

Vintage Journal Beautiful Garden Flower Embossed Leather-Antique Handmade Dec...

$27.91



VINTAGE Bruker Board DEC W4P3042 for SpectroSpin 250 picture

VINTAGE Bruker Board DEC W4P3042 for SpectroSpin 250

$99.99



HSS 12pcs Valve Seat & Face Cutter 45dec 30dec 20dec for Vintage Car, Bikes ,Jee picture

HSS 12pcs Valve Seat & Face Cutter 45dec 30dec 20dec for Vintage Car, Bikes ,Jee

$235.94







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