|
|
10-09-2008, 02:17 PM
|
#1
|
Thumbs Must Hurt
Join Date: May 2008
Model: 8320
PIN: N/A
Carrier: Tmobile
Posts: 62
|
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
|
|
10-12-2008, 12:13 PM
|
#2
|
Thumbs Must Hurt
Join Date: May 2008
Model: 8320
PIN: N/A
Carrier: Tmobile
Posts: 62
|
bump^
|
Offline
|
|
10-13-2008, 03:16 AM
|
#3
|
Talking BlackBerry Encyclopedia
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
|
show us your code
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
|
Offline
|
|
10-14-2008, 12:38 AM
|
#4
|
Thumbs Must Hurt
Join Date: May 2008
Model: 8320
PIN: N/A
Carrier: Tmobile
Posts: 62
|
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
|
|
10-14-2008, 02:54 AM
|
#5
|
Talking BlackBerry Encyclopedia
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
|
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
|
|
10-14-2008, 07:45 AM
|
#6
|
Thumbs Must Hurt
Join Date: May 2008
Model: 8320
PIN: N/A
Carrier: Tmobile
Posts: 62
|
Quote:
Originally Posted by Ivanov
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
|
|
10-14-2008, 08:10 AM
|
#7
|
Talking BlackBerry Encyclopedia
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
|
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
|
|
10-14-2008, 01:16 PM
|
#8
|
Thumbs Must Hurt
Join Date: May 2008
Model: 8320
PIN: N/A
Carrier: Tmobile
Posts: 62
|
Quote:
Originally Posted by Ivanov
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
|
|
10-15-2008, 03:34 AM
|
#9
|
Talking BlackBerry Encyclopedia
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
|
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
|
|
10-15-2008, 09:58 AM
|
#10
|
Thumbs Must Hurt
Join Date: May 2008
Model: 8320
PIN: N/A
Carrier: Tmobile
Posts: 62
|
Quote:
Originally Posted by Ivanov
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
|
|
01-29-2009, 04:49 AM
|
#11
|
Thumbs Must Hurt
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: AT
Posts: 81
|
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
|
|
01-29-2009, 12:54 PM
|
#12
|
Thumbs Must Hurt
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: AT
Posts: 81
|
Any Idea please?
|
Offline
|
|
|
|