Skip to content Skip to sidebar Skip to footer

Autocompletetextview Stops Listening To Onitemclick

Existing code and xml The code fromAutoComplete = new AutoComplete( this, R.layout.fromautocomplete, R.id.fromautocomplete); fromAutoComplete.setNotifyOnChange(true

Solution 1:

Got it working,

Fixes

  1. Gave a id to my LinearLayout
  2. Used the layout id in my onItemClick
  3. Used R.layout.<file> in the constructor

XML (R.layout.fromautocomplete)

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/toautocompleteLayout"android:layout_width="fill_parent"android:layout_height="wrap_content" ><TextViewandroid:id="@+id/toautocomplete"

Code

fromAutoComplete = newAutoComplete(this,
         R.layout.fromautocomplete,
                R.id.fromautocomplete);
        fromAutoComplete.setNotifyOnChange(true);

OnItemClick

@OverridepublicvoidonItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        if (view.getId() == R.id.fromautocompleteLayout) {

Solution 2:

You need to get Textview from LinearLayout

@OverridepublicvoidonItemClick(AdapterView<?> parent, View view, int position, long id) {

                Viewv= (TextView)((LinearLayout )view).getChildAt(0);
                Strings= ((TextView) v).getText().toString();
               //Do something with string s
}

Post a Comment for "Autocompletetextview Stops Listening To Onitemclick"