BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 10-09-2008, 02:17 PM   #1
nyte3k
Thumbs Must Hurt
 
nyte3k's Avatar
 
Join Date: May 2008
Model: 8320
PIN: N/A
Carrier: Tmobile
Posts: 62
Default Searchable ListField

Please Login to Remove!

does anyone have a code sample of this, similar to the BlackBerry MemoPad. All the examples i find using the listField seem to not to implement this functionality.

I've added a fieldListener to a editField, which then calls the indexOfList method, but still does not work.
Offline  
Old 10-12-2008, 12:13 PM   #2
nyte3k
Thumbs Must Hurt
 
nyte3k's Avatar
 
Join Date: May 2008
Model: 8320
PIN: N/A
Carrier: Tmobile
Posts: 62
Default

bump^
Offline  
Old 10-13-2008, 03:16 AM   #3
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

show us your code
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
Offline  
Old 10-14-2008, 12:38 AM   #4
nyte3k
Thumbs Must Hurt
 
nyte3k's Avatar
 
Join Date: May 2008
Model: 8320
PIN: N/A
Carrier: Tmobile
Posts: 62
Cool

the code is basically like this...

Code:
public class myScreen extends MainScreen implements ListFieldCallback{
private ListField listField = null;
private Vector myVector = null;

public myScreen(){
 myVector = new Vector();
 myVector.addElement("SomeString");
 myVector.addElement("AnotherString");
 listField = new ListField(myVector.size());

 listField.setCallback(this);
 listField.setSearchable(true);
 add(listField);
}

public Object get(ListField listField, int index){
		return myVector.elementAt(index);
	}
	
	public int getPreferredWidth(ListField listField){
		return Display.getWidth();
	}
	
	public int indexOfList(ListField listField, String prefix, int start){
		return myVector.indexOf(prefix, start);
	}
	
	public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width){
		String theString = (String)get(listField, index);
		graphics.drawText(theString, 0, y, 0, width);
	}

Looked through a bunch of examples and couldn't find one that worked. I also tried using keyChar on the listField, and that yielded nothing, and also added a BasicEditField and added a field change listener, but that did not work either.
Offline  
Old 10-14-2008, 02:54 AM   #5
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

show the version with the additional editfield and the fieldchangelistener - it was the right direction.
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
Offline  
Old 10-14-2008, 07:45 AM   #6
nyte3k
Thumbs Must Hurt
 
nyte3k's Avatar
 
Join Date: May 2008
Model: 8320
PIN: N/A
Carrier: Tmobile
Posts: 62
Default

Quote:
Originally Posted by Ivanov View Post
show the version with the additional editfield and the fieldchangelistener - it was the right direction.
Code:
public class myScreen extends MainScreen implements ListFieldCallback, FieldChangeListener{
private ListField listField = null;
private Vector myVector = null;
private BasicEditField editField;

public myScreen(){
 editField = new BasicEditField("Find: ", "");
 myVector = new Vector();
 myVector.addElement("SomeString");
 myVector.addElement("AnotherString");
 listField = new ListField(myVector.size());

 listField.setCallback(this);
 listField.setSearchable(true);
 add(listField);
}

public void fieldChanged(Field field, int context){
		if(field == editField){
			String prefix = editField.getText();
			indexOfList(listField, prefix, 0);
		}
	}

public Object get(ListField listField, int index){
		return myVector.elementAt(index);
	}
	
	public int getPreferredWidth(ListField listField){
		return Display.getWidth();
	}
	
	public int indexOfList(ListField listField, String prefix, int start){
		return myVector.indexOf(prefix, start);
	}
	
	public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width){
		String theString = (String)get(listField, index);
		graphics.drawText(theString, 0, y, 0, width);
	}
Offline  
Old 10-14-2008, 08:10 AM   #7
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

allright if using setSearchable of the ListField just update your indexOfList function and remove the editfield (actually it's not added to the screen at all)

if you want to do it like in memopad showing only the matching results...
in yuour FieldChangeListener iterate through the Data-Vector elements and copy those which starts with the String from the EditField to the second Vector which will be then used in the ListField

Code:
	public int indexOfList(ListField listField, String prefix, int start){
		return listField.indexOfList(prefix, start);
	}
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
Offline  
Old 10-14-2008, 01:16 PM   #8
nyte3k
Thumbs Must Hurt
 
nyte3k's Avatar
 
Join Date: May 2008
Model: 8320
PIN: N/A
Carrier: Tmobile
Posts: 62
Default

Quote:
Originally Posted by Ivanov View Post
allright if using setSearchable of the ListField just update your indexOfList function and remove the editfield (actually it's not added to the screen at all)

if you want to do it like in memopad showing only the matching results...
in yuour FieldChangeListener iterate through the Data-Vector elements and copy those which starts with the String from the EditField to the second Vector which will be then used in the ListField

Code:
	public int indexOfList(ListField listField, String prefix, int start){
		return listField.indexOfList(prefix, start);
	}

going with the latter (memopad-like), nothing occurs. How did you go about passing your second vector to the listField? Was a paint or invalidate done?
Offline  
Old 10-15-2008, 03:34 AM   #9
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

This a quick and very dirty solution extending your original code...
Normally you should extend the ListField implementing the ListFieldCallback and do some more checks on input values to be more generic, so the new Field Class can be reused in the future and separated from the Screen layout.

Code:
public class SearchableListScreen extends MainScreen implements ListFieldCallback,
        FieldChangeListener
{
    private ListField listField = null;
    private Vector myVector = null;
    private BasicEditField editField;
    
    private Vector vData = null;

    public SearchableListScreen()
    {
        editField = new BasicEditField("Find: ", "");
        editField.setChangeListener(this);
        vData = new Vector();        
        vData.addElement("SomeString");
        vData.addElement("AnotherString");
        vData.addElement("AnatherString");
        vData.addElement("AnitherString");
        myVector = new Vector(vData.size());
        
        for (Enumeration e = vData.elements(); e.hasMoreElements();)
        {
            String entry = (String)e.nextElement();
            myVector.insertElementAt(entry, 0);
        }
        
        listField = new ListField(myVector.size());
        listField.setCallback(this);
        
        add(editField);
        add(listField);
    }

    public void fieldChanged(Field field, int context)
    {
        if (field == editField)
        {
            String prefix = editField.getText();
            
            myVector.removeAllElements();
            
            for (Enumeration e = vData.elements(); e.hasMoreElements(); )
            {
                String entry = (String)e.nextElement();
                
                if (entry.startsWith(prefix))
                {
                    myVector.insertElementAt(entry, 0);
                }
            }
            
            listField.setSize(myVector.size());
            listField.invalidate();
        }
    }

    public Object get(ListField listField, int index)
    {
        return myVector.elementAt(index);
    }

    public int getPreferredWidth(ListField listField)
    {
        return listField.getWidth();
    }

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

    public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width)
    {
        String theString = (String) get(listField, index);
        graphics.drawText(theString, 0, y, 0, width);
    }
}
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
Offline  
Old 10-15-2008, 09:58 AM   #10
nyte3k
Thumbs Must Hurt
 
nyte3k's Avatar
 
Join Date: May 2008
Model: 8320
PIN: N/A
Carrier: Tmobile
Posts: 62
Thumbs up

Quote:
Originally Posted by Ivanov View Post
This a quick and very dirty solution extending your original code...
Normally you should extend the ListField implementing the ListFieldCallback and do some more checks on input values to be more generic, so the new Field Class can be reused in the future and separated from the Screen layout.

Code:
public class SearchableListScreen extends MainScreen implements ListFieldCallback,
        FieldChangeListener
{
    private ListField listField = null;
    private Vector myVector = null;
    private BasicEditField editField;
    
    private Vector vData = null;

    public SearchableListScreen()
    {
        editField = new BasicEditField("Find: ", "");
        editField.setChangeListener(this);
        vData = new Vector();        
        vData.addElement("SomeString");
        vData.addElement("AnotherString");
        vData.addElement("AnatherString");
        vData.addElement("AnitherString");
        myVector = new Vector(vData.size());
        
        for (Enumeration e = vData.elements(); e.hasMoreElements();)
        {
            String entry = (String)e.nextElement();
            myVector.insertElementAt(entry, 0);
        }
        
        listField = new ListField(myVector.size());
        listField.setCallback(this);
        
        add(editField);
        add(listField);
    }

    public void fieldChanged(Field field, int context)
    {
        if (field == editField)
        {
            String prefix = editField.getText();
            
            myVector.removeAllElements();
            
            for (Enumeration e = vData.elements(); e.hasMoreElements(); )
            {
                String entry = (String)e.nextElement();
                
                if (entry.startsWith(prefix))
                {
                    myVector.insertElementAt(entry, 0);
                }
            }
            
            listField.setSize(myVector.size());
            listField.invalidate();
        }
    }

    public Object get(ListField listField, int index)
    {
        return myVector.elementAt(index);
    }

    public int getPreferredWidth(ListField listField)
    {
        return listField.getWidth();
    }

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

    public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width)
    {
        String theString = (String) get(listField, index);
        graphics.drawText(theString, 0, y, 0, width);
    }
}
Well that certainly did the trick...one crucial thing I somehow forgot to add last time was editField.setChangeListener(this);

...I really should get some sleep
Offline  
Old 01-29-2009, 04:49 AM   #11
taqi.mir
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: AT
Posts: 81
Default

Hi,


Instead of deleting the list items,i just want to start selection automatically from the index where prefix(text from the BasicEditField)matches with list item for that i have written below code so am i doing something wrong ?

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;
//listField.invalidate();
}
}
}
listField.indexOfList(prefix,1);


}
}
h

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;
//listField.invalidate();
}
}
}
listField.indexOfList(prefix,1);


}
}
Offline  
Old 01-29-2009, 12:54 PM   #12
taqi.mir
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: AT
Posts: 81
Default

Any Idea please?
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


LOT OF 10 SIEMENS QA120AFC  20A AFCI BREAKER (with pigtail wire) NEW picture

LOT OF 10 SIEMENS QA120AFC 20A AFCI BREAKER (with pigtail wire) NEW

$398.99



USED SIEMENS MCC BREAKER HANDLE MECHANISM 25-135-017-521 picture

USED SIEMENS MCC BREAKER HANDLE MECHANISM 25-135-017-521

$170.00



LOT OF 10 SIEMENS Q120DFN 20A DUAL AFCI/GFCI PLUG ON NEUTRAL BREAKER BRAND NEW picture

LOT OF 10 SIEMENS Q120DFN 20A DUAL AFCI/GFCI PLUG ON NEUTRAL BREAKER BRAND NEW

$429.99



LOT OF 10 SIEMENS QA120AFCN 20A AFCI PLUG ON NEUTRAL (NO WIRE)  NEW picture

LOT OF 10 SIEMENS QA120AFCN 20A AFCI PLUG ON NEUTRAL (NO WIRE) NEW

$327.99



LOT OF 10 SIEMENS QA115AFCN 15A AFCI PLUG ON NEUTRAL (NO PIGTAIL WIRE) NEW picture

LOT OF 10 SIEMENS QA115AFCN 15A AFCI PLUG ON NEUTRAL (NO PIGTAIL WIRE) NEW

$348.99



LOT OF 10 SIEMENS QA115AFC AFCI 15A BREAKER (with pigtail wire) NEW picture

LOT OF 10 SIEMENS QA115AFC AFCI 15A BREAKER (with pigtail wire) NEW

$389.99







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