17

My AutoCompleteTextView doesn't work when I enter first character in textbox but starts showing dropdown when I enter second character. What could be the reason?

<AutoCompleteTextView
    android:id="@+id/autocomplete_name"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_weight="7"
    android:background="@drawable/edittextback"
    android:ems="10"
    android:textSize="15sp"
    android:hint="@string/codehint"
    android:textColorHint="@color/hintgrey"
    android:dropDownWidth="fill_parent"
    android:paddingRight="30dp"
    android:paddingLeft="10dp"
    android:singleLine="true"
    android:ellipsize="end"
/>
Marko
  • 20,385
  • 13
  • 48
  • 64
Figen Güngör
  • 12,169
  • 14
  • 66
  • 108

4 Answers4

60

You will need to set the completionThreshold property of your autoCompleteView to 1.

<AutoCompleteTextView 
    android:id="@+id/someID" 
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:completionThreshold="1" />

Or for doing it dynamically through code use

mAutoCompleteTextView.setThreshold(1)

Happy Coding :)

nobalG
  • 4,544
  • 3
  • 34
  • 72
  • @nobalG i am facing issue like this http://pastie.org/10678820# , problem is that there if i enter ap then those list items have ap those are not comes and display i want to show those items start from ap word or any inputted word – Amitsharma Jan 09 '16 at 08:22
  • @amitsharma can you elaborate? – nobalG Jan 09 '16 at 08:37
  • @nobalG please look at editted if i enter ap then those listitems start with ap those should display in list this is the issue – Amitsharma Jan 09 '16 at 08:49
  • @amitsharma please show some code, or ask a question here at stackoverflow and send me a link of the question so that i can see it. – nobalG Jan 09 '16 at 09:03
  • @amitsharma The component in which you are entering the input is an editText? right? – nobalG Jan 09 '16 at 09:08
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/100223/discussion-between-amitsharma-and-nobalg). – Amitsharma Jan 09 '16 at 10:03
  • docker swarm join --token SWMTKN-1-1j5m7t669fnz8hbwlui371zeghoahhixz06eu57zmjmmwrgibl-6xk88fbhrbq38az6py8j82rd7 192.168.1.122:2377 – nobalG Oct 03 '20 at 09:34
2

use i java code

autoComplete.setThreshold(1);

or in xml

android:completionThreshold="1"
Naveen Tamrakar
  • 3,349
  • 1
  • 19
  • 28
0
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView;
import android.widget.Toast;

public class MainActivity extends Activity {

     private AutoCompleteTextView autoComplete;
     private MultiAutoCompleteTextView multiAutoComplete;
     private ArrayAdapter<String> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // get the defined string-array 
        String[] colors = getResources().getStringArray(R.array.colorList);

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

        autoComplete = (AutoCompleteTextView) findViewById(R.id.autoComplete);
        multiAutoComplete = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoComplete);

        // set adapter for the auto complete fields
        autoComplete.setAdapter(adapter);
        multiAutoComplete.setAdapter(adapter);

        // specify the minimum type of characters before drop-down list is shown
        autoComplete.setThreshold(1);
        multiAutoComplete.setThreshold(2);
        // comma to separate the different colors
        multiAutoComplete.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

        // when the user clicks an item of the drop-down list
        multiAutoComplete.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                 Toast.makeText(getBaseContext(), "MultiAutoComplete: " +
                            "you add color "+arg0.getItemAtPosition(arg2),
                            Toast.LENGTH_LONG).show();
            }
        });
    }

}
koutuk
  • 832
  • 1
  • 8
  • 17
  • i am geting this pastie.org/10678820# , problem is that there if i enter ap then those list items have ap those are not comes and display i want to show those items start from ap word or any inputted word.. – Amitsharma Jan 09 '16 at 08:24
0

If you want after clicking on MaterialAutoCompleteTextView Open the dialog

you must set the completionThreshold value to 0 And inputType value to none.

you can also increase the same field for the minimum number of characters.

don't forget set inputType to text or number

 <com.google.android.material.textfield.MaterialAutoCompleteTextView
                android:layout_width="match_parent"
                android:layout_height="45dp"
                android:completionThreshold="0" <-- This line
                android:ems="10"
                android:inputType="none" />

I hope hep

Javid Sattar
  • 749
  • 8
  • 14