我是机器人的初学者。当我试图将SQLite数据库中的值填充到AutoCompleteTextView时,我遇到了问题。通过下面的函数getAllFnames()*shown,我从数据库获得了一个字符串数组的值。但是AutoCompleteTextView并没有在run time..anybody上给出任何建议来帮助me.....codes获得below..please check..thank .(Log显示了一些过滤问题!)
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;
}在文本视图侧
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());
}发布于 2012-12-05 12:17:36
试试这段代码。使用数据数组代替月份数组。而是使用数组来代替大小为1000的数组。更有效率。
公共类自动完成扩展活动{
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);
}
}发布于 2012-12-05 12:17:49
你用这个
ArrayAdapter<String> fnameAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, Fname);尝尝这个。谢谢。
发布于 2012-12-05 12:20:48
我在这里看到的唯一问题是(假设您从DB获得值)。
ArrayAdapter<String> fnameAdapter=new ArrayAdapter<String>(this,R.layout.list,Fname);代之以
myAutoComplete.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, Fname));https://stackoverflow.com/questions/13722879
复制相似问题