2014-09-09 4 views
0

Существующий код и XML КодексаAutoCompleteTextView перестает слушать onItemClick

fromAutoComplete = new AutoComplete(
     this, R.layout.fromautocomplete, 
     R.id.fromautocomplete); 
fromAutoComplete.setNotifyOnChange(true); 
fromAddress = (AutoCompleteTextView) findViewById(R.id.fromAddress); 
fromAddress.setAdapter(fromAutoComplete); 
fromAddress.setOnItemClickListener(this); 
fromAddress.setOnFocusChangeListener(this); 
fromAddress.setOnClickListener(this); 

XML-

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/fromautocomplete" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:ellipsize="none" 
    android:maxLines="2" 
    android:minLines="2" 
    android:singleLine="false" 
    android:text="sample text, a lot of text to encourage wrap text"/> 

Мне нужно автозаполнения, чтобы обернуть текст, на ListView. Поэтому я добавляю LinearLayout вокруг моего автозаполнения. Это работает. Теперь список в автозаполнении теперь имеет завернутый текст. , но по выбору не из моих обратных вызовов не называется.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 
<TextView 
    android:id="@+id/fromautocomplete" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:maxLines="2" 
    android:minLines="2" 
    android:scrollHorizontally="false" 
    android:singleLine="false" 
    android:text="sample text, a lot of text to encourage wrap text"/> 
</LinearLayout> 

ответ

0

Понял работает,

багов

  1. Дал id к моему LinearLayout
  2. Используется макет id в моем onItemClick
  3. Используется R.layout.<file> в конструкторе

XML (R.layout.fromautocomplete)

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

    <TextView 
     android:id="@+id/toautocomplete" 

Код

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

OnItemClick

@Override 
    public void onItemClick(AdapterView<?> parent, View view, int position, 
      long id) { 
     if (view.getId() == R.id.fromautocompleteLayout) { 
0

Вы должны получить TextView от LinearLayout

@Override 
public void onItemClick (AdapterView<?> parent, View view, int position, long id) { 

       View v = (TextView)((LinearLayout)view).getChildAt(0); 
       String s = ((TextView) v).getText().toString(); 
       //Do something with string s 
} 
Смежные вопросы