1

我正在开发一个应用程序,因为我在黑莓中使用自动完成字段。而不是演示中的字符串集合,例如我想使用向量集合。

现在我想知道,当我在该字段中输入任何值时,它会根据输入返回结果。现在我想在用户点击查询返回的 3/4 结果中的特定结果时采取行动。那怎么可能呢?

4

2 回答 2

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.
     }
 }

};

于 2013-10-23T12:14:14.520 回答
0

尝试运行此代码。我已经处理过这个有一个数据库并过滤掉名称的问题。根据您的需要进行更改。希望它有所帮助。

      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); 


    }
于 2012-05-29T17:58:17.723 回答