首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android:AutoCompleteTextView

Android:AutoCompleteTextView
EN

Stack Overflow用户
提问于 2012-12-05 12:05:25
回答 4查看 146关注 0票数 1

我是机器人的初学者。当我试图将SQLite数据库中的值填充到AutoCompleteTextView时,我遇到了问题。通过下面的函数getAllFnames()*shown,我从数据库获得了一个字符串数组的值。但是AutoCompleteTextView并没有在run time..anybody上给出任何建议来帮助me.....codes获得below..please check..thank .(Log显示了一些过滤问题!)

代码语言:javascript
复制
 public String[] getAllFnames() {

     database=open();
     Fname=new String[1000];
     int i=0;
Cursor cursor = database.query(DbCreation.PATIENT_TABLE,Columns, null, null, null, null, null);
          cursor.moveToFirst();
          while (!cursor.isAfterLast()) {
          Fname[i]=cursor.getString(1).toString();
          Log.v("DataBaseValues...", Fname[i]);
          cursor.moveToNext();
          i++;
        }

        // Make sure to close the cursor
        cursor.close();
        return Fname;
}

在文本视图侧

代码语言:javascript
复制
      Fname=ss.getAllFnames();//here Fname is a string array
             //"ss" is the object of class where method getAllFname()  is placed.
ArrayAdapter<String> fnameAdapter=new ArrayAdapter<String>(this,R.layout.list,Fname);

     fnameSearch.setThreshold(1);//fnameSearch is the AutoCompleteTextView

     fnameSearch.setAdapter(fnameAdapter);

     fnameSearch.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
EN

回答 4

Stack Overflow用户

发布于 2012-12-05 12:17:36

试试这段代码。使用数据数组代替月份数组。而是使用数组来代替大小为1000的数组。更有效率。

公共类自动完成扩展活动{

代码语言:javascript
复制
 static final String[] Months = new String[]{
    "January","February","March","April","May","June","July","August",
    "September","October","November","December"
    };

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.autocomplete);

    ArrayAdapter<String> monthArray = new ArrayAdapter<String>(this,
            android.R.layout.simple_dropdown_item_1line, Months);


    final AutoCompleteTextView textView = (AutoCompleteTextView)findViewById(R.id.testAutoComplete);
            textView.setAdapter(monthArray);

   }

}
票数 0
EN

Stack Overflow用户

发布于 2012-12-05 12:17:49

你用这个

代码语言:javascript
复制
ArrayAdapter<String> fnameAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_dropdown_item_1line, Fname);

尝尝这个。谢谢。

票数 0
EN

Stack Overflow用户

发布于 2012-12-05 12:20:48

我在这里看到的唯一问题是(假设您从DB获得值)。

代码语言:javascript
复制
ArrayAdapter<String> fnameAdapter=new ArrayAdapter<String>(this,R.layout.list,Fname);

代之以

代码语言:javascript
复制
myAutoComplete.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, Fname));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13722879

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档