BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 01-29-2009, 06: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, 06: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, 06: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





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