0

I have login activity where username is read from editText field. How can I make such an functionality to suggest usernames that have been already logged in from the same device?

stefan.stt
  • 2,357
  • 5
  • 24
  • 47

2 Answers2

2

Use an AutoCompleteTextView instead of normal EditText

Save previous usernames in a sqlite db and then pull from that for the AutoCompleteTextView.

Here is some example code that should get you started.

AutoCompleteTextView textView = (AutoCompleteTextView) 

findViewById(R.id.autocomplete_usernames);

String[] usernames = db.getUsernames();

ArrayAdapter<String> adapter =
    new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usernames);

textView.setAdapter(adapter);
TomD
  • 604
  • 1
  • 7
  • 22
1

For fast and easy implementation, you can use Android SharedPreferences in which you can easily save your previous input string. Read the documentation. It is well explained.

But if you want to save an array/arraylist, you can use also SharedPreferences. Read this answer