user1831490
user1831490

Reputation:

Can't type in the AutoCompleteTextView In Android

I'm putting a AutoCompleteTextView in my layout, and I can not write anything visible in it! I can not find the solution for this problem.

Here is my Layout:

<AutoCompleteTextView
        android:id="@+id/txtOccupation"
        android:layout_width="510dp"
        android:layout_height="40dp"
        android:layout_below="@+id/datePicker"
        android:layout_toRightOf="@id/lblOccupation"
        android:background="#FFFFFF"
        android:paddingTop="10dp"
        android:paddingBottom="10dp" />

And here is my code to handle the autoCompletion which I write it in the OnCreate():

//---AutoComplete ---
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, Occupations);
                AutoCompleteTextView textView = (AutoCompleteTextView)
                findViewById(R.id.txtOccupation);
                textView.setThreshold(3);
                textView.setAdapter(adapter);

And I have an array in my activity class:

String[] Occupations = {"Software Engineer","Denist","Insustrial Engineer","University Professor","Secretary"};

Upvotes: 2

Views: 2384

Answers (1)

Veerababu Medisetti
Veerababu Medisetti

Reputation: 2755

In Xml put this. in that completionThreshold=1 means, after typind one letter the list displays instead you make it for 2 like that.

<AutoCompleteTextView
     android:id="@+id/autoCompleteTextView_search_location"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_gravity="center_horizontal"
     android:completionThreshold="1"
     android:imeOptions="actionDone"
     android:inputType="text"
     android:paddingLeft="10dp"
     android:singleLine="true"
     android:maxLength="20"
     android:textSize="22px" >
</AutoCompleteTextView>

In Activity it should implements TextWatcher.Then add unimplemented methods for that.And Set the adapter like this.

autoCompleteTextView_search_location.addTextChangedListener(this);
autoCompleteTextView_search_location.setAdapter(new ArrayAdapter<String>(this,
    android.R.layout.simple_dropdown_item_1line,occupations));

Let me know your problem is resolved or not.

Upvotes: 2

Related Questions