android - Add word to user dictionary and retrieve them back from dictionary -
i have few edittexts in application user enters company name, client name, purpose....kinds of things. want add words dictionary programmatically , don't have re-enter whole word everytime, instead dictionary should suggest word once start typing.
i searched on web regarding same , got
userdictionary.words.addword(getactivity(), et_client_name.gettext().tostring(), 1, "", locale);
and need give 2 permissions app:
<uses-permission android:name="android.permission.write_user_dictionary"/> <uses-permission android:name="android.permission.read_user_dictionary"/>
but problem : once add words using above statement; how retrieve dictionary , suggest user user starts typing in.
any or reference tutorials appreciated!
i managed find solution of question own....answering question in hope might reference same kind of issue:
public class homeactivity extends fragment implements textwatcher { string itemclientname[] = {}; arrayadapter<string> clientnameadapter; arraylist<string> clientnamelist = new arraylist<string>(); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); autocompletetextview et_client_name = (autocompletetextview) findviewbyid(r.id.et_client_name); getfromdictionary(); suggestclientname(); et_client_name.addtextchangedlistener(this); } public void getfromdictionary() { system.out.println("inside getfromdictionary"); contentresolver resolver = getactivity().getcontentresolver(); string[] projection = new string[]{basecolumns._id, userdictionary.words.word}; cursor = resolver.query(userdictionary.words.content_uri, projection, null, null, null); if (cursor.movetofirst()) { { long id = integer.parseint(cursor.getstring(0)); word = cursor.getstring(1); // prepare list autocompletion system.out.println("inside preparemylist" + word); if (!clientnamelist.contains(word)) clientnamelist.add(word); system.out.println("clientnamelist::" + clientnamelist); system.out.println("word dictionary is::" + word); // meaningful } while (cursor.movetonext()); } } public void suggestclientname() { string newadd1 = et_client_name.gettext().tostring(); if (!clientnamelist.contains(newadd1)) { clientnamelist.add(newadd1); // update autocomplete words clientnameadapter = new arrayadapter<string>(getactivity(), android.r.layout.simple_dropdown_item_1line, clientnamelist); et_client_name.setadapter(clientnameadapter); } // display words in mylist reference string s = ""; (int = 0; < clientnamelist.size(); i++) { s += clientnamelist.get(i) + "\n"; } } }
Comments
Post a Comment