uzyskiwanie listy wcześniej wprowadzonych ciągów pod tekstem edycji w Androidzie „tak jak w polu nazwy użytkownika niektórych wiadomości e-mail / stron internetowych”
Chcę jakieś wskazówki. Nie mam jasnego zrozumienia tego. Więc proszę...
Oto mój tekst w formacie XML:
<EditText
android:id="@+id/editTextName"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_margin="3dp"
android:hint="Insert Name"
android:onClick="surNameEditTextClick" />
Kod, aby uzyskać ciąg wejściowy tekstu edycji:
EditText nameText = (EditText) findViewById(R.id.editTextName);
String name = nameText.getText().toString();
Zapisywanie łańcucha znaków na liście tablicy ciągu:
ArrayList<String> nameArrayList = new ArrayList<String> ; //created globally
if(!(nameArrayList.contains(name))){
//Adding input string into the name array-list
nameArrayList.add(name) ;
}
Umieszczenie tej listy tablic w preferencjach współdzielonych:
SharedPreferences saveGlobalVariables = getSharedPreferences(APP_NAME, 0);
SharedPreferences.Editor editor = saveGlobalVariables.edit();
editor.putStringSet("name", new HashSet<String>(surNameArrayList));
editor.commit();
Przywracanie wszystkich danych Shared-Preferences na listę tablicową, gdy program ładuje się (w onCreate ()):
SharedPreferences loadGlobalVariables = getSharedPreferences(APP_NAME, 0);
nameArrayList = new ArrayList<String>(loadGlobalVariables.getStringSet("name", new HashSet<String>()));
Teraz, jak uzyskać te dane w jakiejś formie widoku w ramach tego tekstu edycji. Widziałem różne metody, ale nie rozumiałem wyraźnie. Jeśli korzystam z
EditText mNameEditText;
mNameEditText = (EditText)findViewById(R.id.editTextName);
mNameEditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s){
}
public void beforeTextChanged(CharSequence s, int start, int count, int after){
}
public void onTextChanged(CharSequence s, int start, int before, int count){
}
});
Więc jaki fragment kodu będzie tutaj używany? Który textView lub widok listy powinien być używany i gdzie ??? Nie jestem w stanie tego zrozumieć. Jeśli dostępna jest jakakolwiek inna metoda, podaj tutaj. pozdrowienia,