开发者

Android AutoCompleteTextView update

开发者 https://www.devze.com 2023-03-09 16:22 出处:网络
I have an activity which has two inputs : one for city and the other for location. I am storing the city and location information in sqlite table whenever the user request a search operation.

I have an activity which has two inputs : one for city and the other for location. I am storing the city and location information in sqlite table whenever the user request a search operation.

Now, i want whenever the user inputs the ci开发者_开发问答ty(which is a autosuggest), the autosuggest options in location should automatically update. The input widget for location and city are both AutoCompleteTextView.

How can this be done?

Rgds, Sapan


you just need to provide a CursorAdapter to the AutoCompleteTextView, e.g. a SimpleCursorAdapter (though the SimpleCursorAdapter was buggy when i tried it).

Cursor cursor = getCityCursor();
int ids = int[]{R.id.autocomplete_list_item};

SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, 
  R.layout.list_item, cursor, new String[]{DB.COL_CITIES});

AutoCompleteTextView actvCities = (AutoCompleteTextView)findViewById(R.id.cities);
actvCitites.setAdapter(cursorAdapter);

the getCityCursor(); method should provide a cursor obtained by a SQLiteDatabase.query().

update: the "buggy" SimpleCursorAdapter i mentioned earlier isn't. just provide a CursorToStringConverter. dan breslau wrote a pretty nice article about AutoCompleteTextView and the SimpleCursorAdapter here.

0

精彩评论

暂无评论...
验证码 换一张
取 消