Here must check
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.names);
that names
is the id of your AutoCompleteTextView
in your activity_main.xml
file.
Because your logcat clearly says that you have a ClassCast Exception
. So must check the id in your activity_main.xml
file.
So change here from
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.names);
to
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.id.names,presidents);
You need to apply your Threshold
to 1 instead of 3 because
When threshold is less than or equals 0, a threshold of 1 is applied.
UPDATE:
You have to change this from
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.id.names,presidents);
to
ArrayAdapter<String>p = new ArrayAdapter<String>(YourActivityName.this, R.layout.customlayout, R.id.names, presidents);
Where customlayout
is the layout in which your TextView
will be which id is names
.