n~droid generation

Taking ndroid for a ride…

Turn EditText to AutoComplete or to AutoCompletePreference

strong>Turn EditText to AutoComplete, Edittext AutoComplete or an AutoCompletePreference


This is a howTo you turn an EditTextPreference to an AutoComplete,
So you can, for instance, display a folders list of you eternal card.

Your application uses default OR user preferences.
One of those preferences is choosing a path of a folder on the device’s sdCard.

You wish to enable a quick and easy way to access that folders list.

For this task we will:

  • Extend EditTextPreference.
  • Get a folders list from our sdCard.
  • Set an ArrayAdapter to hold the list and show as AutoComplete on our EditTextPreference.

So you class should be defined like this:

As good debug practice I always add the following tag:

Then we need to declare the AutoCompleteTextView:

As mentioned at the begining our class will use 2 more variables to hold the folders list:

  • Gets the list from device’s sdCard:

  •  Holds the list of directories is an array:

The AutoCompletePreference Constructor:

  1. Will call Super to inherit & construct needed methods.
  2. Will instantiate mEditText.
  3. Will set setThreshold of AutoComplete.
  4. Will fill ArrayAdapter.
  5. Will set mEditText adapter to ArrayAdapter – Note that the adapter gets its content from a method called sdFolderScanToListArray();
Here is the code:

Our next method will get an array of folder name from device’s sdCard:

* Note that you will need to construct a class named sdFolderStructure to get folders from sdCard,

OR look it up on my blog here

Next we will need to use the overridden method onBindDialogView,  to bind the dialog view to our AutoCompleteTextView,
While enabling the user to get AutoComplete while hitting the keyboard.

And the last method is for when the user gets his folder into the mEditText, and leaves the dialog box,

We need to get the folder name/value.

For that task we will be using the onDialogClosed overridden method as follows:

Hope you find this usefull….

Please contribute either by Donating with PayPal or Flatter Me a Little


Full code can be found here: AutoCompletePreference.java

The SdFolderStructure Class is here: SdFolderStructure  – Getting folder structure from android sdCard device

Development & Design: http://nwg.co.il
  • Google+
  • LinkedIn