1

重複しているように見えるかもしれませんが、そうではありません。

AutoCompleteTextView私のレイアウトには 2 があります。送信元アドレス、送信先アドレス。どちらがドロップダウン リストを開始したかを知る必要があります。

どちらも同じアイテム レイアウトを使用していたので、複製して試してみましたが、まだうまくいきません。

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 の id がそのような役に立たない値を返すのでしょうか?

ここで本当に基本的なことが欠けています。

4

1 に答える 1

0

I think I figured it out. The answer is 2 fold.

  1. The id value returned by onItemClick returns 0 for the first autocomplete, and 1 for the second autocomplete

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

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

  2. The layout textview's should have id's. That is returned in the view parameter of onItemClick

For 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"/>

For 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"/>
于 2013-07-02T12:13:51.963 に答える