我正在开发一个应用程序,因为我在黑莓中使用Auto Complete Field。 而不是在演示中收集字符串我想使用矢量集合。
现在我想知道当我在该字段中输入任何值时,我将根据输入返回结果。现在我想在用户点击查询返回的3/4结果中的特定结果时采取行动。那怎么可能呢?
答案 0 :(得分:0)
尝试运行此代码。我已经使用db并过滤掉了名称。 根据您的需要进行更改。希望它有所帮助。
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);
}
答案 1 :(得分:0)
使用此
AutoCompleteField autoCompleteField = new AutoCompleteField(filterList) {
public void onSelect(Object selection, int type) {
super.onSelect(selection, type);
if(selection != null) {
String selectionAsString = getEditField().getText();
// Do whatever else you need to do with the String.
}
}
};