2013-07-02 2 views
1

Это может показаться duplicate, но это не так.2 AutoCompleteTextView, как узнать, какой вид был выбран

У меня есть 2 AutoCompleteTextView в моем расположении. От адреса, адреса. Мне нужно знать, какой из них инициировал выпадающий список.

Поскольку оба использовали один и тот же макет элемента, я продублировал его и пытался, но все равно не повезло.

Инициализация AutoCompleteTextView «ы

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

    toAutoComplete = new AutoComplete(this, R.layout.toautocomplete); 
    toAutoComplete.setNotifyOnChange(true); 
    toAddress = (AutoCompleteTextView) findViewById(R.id.toAddress); 
    toAddress.setAdapter(toAutoComplete); 
    toAddress.setOnItemClickListener(this); 
    toAddress.setOnItemSelectedListener(this); 

Обратите внимание на R.layout.toautocomplete и R.layout.fromautocomplete

Оба являются идентичными, как показано ниже.

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_marginTop="15dp" 
android:minLines="3" 
android:layout_marginBottom="15dp" 
android:textSize="15dp" 
android:text="sample text" 
android:marqueeRepeatLimit="marquee_forever"/> 

Для отладки значения, я поместил некоторые высказывания Вход

@Override 
public void onItemSelected(AdapterView<?> parent, View who, int position, long id) { 
    Log.e("Taxeeta", ">"+parent.getId()+":"+who.getId()+":"+id) ; 
} 

@Override 
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {  
    Log.e("Taxeeta", parent.getId()+":"+view.getId()+":"+id) ; 
} 

Выход бревна

07-02 17: 24: 14,773: E/Taxeeta (12103) : -1: -1: 0

Откровенно говоря, это просто отстой, почему id для родителя, представления и идентификатора возвращает такие бесполезные значения?

У меня отсутствует кое-что действительно основное.

ответ

0

Я думаю, что понял. Ответ в 2 раза.

  1. id значение, возвращаемое onItemClick возвращается для первого автозаполнения и для второго автозаполнения

    07-02 17: 24: 14.773: Е/Taxeeta (12103): -1: -1: 0

    07-02 17: 24: 14.773: Е/Taxeeta (12103): -1: -1: 1

  2. В макете textview должны быть id. То возвращается в вид параметра onItemClick

Для FromLayout

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/fromautocomplete" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_marginTop="15dp" 
android:minLines="3" 
android:layout_marginBottom="15dp" 
android:textSize="15dp" 
android:text="sample text" 
android:marqueeRepeatLimit="marquee_forever"/> 

Для ToLayout

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/toautocomplete" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_marginTop="15dp" 
android:minLines="3" 
android:layout_marginBottom="15dp" 
android:textSize="15dp" 
android:text="sample text" 
android:marqueeRepeatLimit="marquee_forever"/> 
Смежные вопросы