Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
Posts: 77
Registered: ‎05-21-2012
My Device: 9900

Re: Autocomplete textfield

Perfect!
Regular Contributor
Posts: 77
Registered: ‎05-21-2012
My Device: 9900

Re: Autocomplete textfield

I have one small glitch in my interface.I have succesffuly been able to get a proper width of auto field but i now want to reduce the height a bit.I ideally want to have width as 300 and height as 20.

Your suggestion of using return Display.getWidth()/2; infact gave me a width of that size.

Since i have used other components in my form which hold editfield boxes of that size, this autocomplete field looks bigger than those.

I have used this to kinda set this auto field same as their size but no luck

final AutoCompleteField TextField1 = new AutoCompleteField(filterLst)
{
public void sublayout(int maxWidth, int maxHeight)
{
//super.sublayout(getPreferredWidth(), getPreferredHeight());
//setExtent(getPreferredWidth(), getPreferredHeight());
super.sublayout(Math.min(maxWidth, 300), Math.min(maxHeight, 20));
}
};
Any idea.
Highlighted
New Developer
Posts: 47
Registered: ‎05-11-2012
My Device: Blackberry Bold 9930
My Carrier: Tmobile

Re: Autocomplete textfield

Hi techie,

did this code work for you?

 

Try to run this code

 

import java.util.Vector;

import net.rim.device.api.collection.util.*;
import net.rim.device.api.database.Cursor;
import net.rim.device.api.database.Database;
import net.rim.device.api.database.DatabaseFactory;
import net.rim.device.api.database.Row;
import net.rim.device.api.database.Statement;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;

 


public class AutoCompleteFieldDemo extends UiApplication
{

public static void main(String[] args)
{

AutoCompleteFieldDemo app = new AutoCompleteFieldDemo();
app.enterEventDispatcher();
}



public AutoCompleteFieldDemo()
{
pushScreen(new AutoCompleteFieldDemoScreen());
}


public static String[] getDataFromDB()
{
Vector names = new Vector();

try
{


Database db = DatabaseFactory.openOrCreate("database1.db");
Statement statement1 = db.createStatement("SELECT name FROM Directory_Items");
statement1.prepare();
statement1.execute();
Cursor c = statement1.getCursor();
Row r;

while(c.next())
{
r = c.getRow();
names.addElement(r.getString(0));

}

statement1.close();
db.close();

}
catch( Exception e )
{
System.out.println( e.getMessage() );
e.printStackTrace();
}

String [] returnValues = new String[names.size()];
for (int i = 0; i < names.size(); i++) {
returnValues[i] = (String) names.elementAt(i);
}

return returnValues;

}


static final class AutoCompleteFieldDemoScreen extends MainScreen
{



AutoCompleteFieldDemoScreen()
{


BasicFilteredList filterLst = new BasicFilteredList();

filterLst.addDataSet(1,getDataFromDB() ,"Names",BasicFilteredList.COMPARISON_IGNORE_CASE)​;
AutoCompleteField autoFld = new AutoCompleteField(filterLst);
add(autoFld);


}

 

If yes, can you please explain how I can find the database. Cause when I tried this code, it keep jumping to the excepting. Thank you in advance!