8

ここで単純なものが欠落している可能性がありますが、非常に長い項目を含むAutoCompleteTextViewがあります。クリックすると、EditTextにテキストが正しく表示され、数行にまたがります。

ただし、ユーザーが選択しているアイテムを確認できるように、ポップアップにも複数行で表示する必要があります。

これが私のカスタムレイアウトです:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:ellipsize="none"
    android:maxLines="100"
    android:scrollHorizontally="false" />

アレイとアダプターの初期化は次のとおりです。

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                R.layout.dropdown_item_wrap_line,
                getResources().getStringArray(R.array.building_descriptions));

mBuildingDesc.setAdapter(adapter);
4

1 に答える 1

13

私の推測では、AutoCompleteTextViewはに制限されてsingleLineいるので、デフォルトでカスタムレイアウトを使用するTextViewとうまくいくはずです。

Layout新しいものを作成して名前を付けてから、次のようにする必要がありcustom_item.xmlます...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView 
        android:id="@+id/autoCompleteItem"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:textSize="14sp"    
        />

</LinearLayout>

次に、AutoCompleteTextViewでAdapterを使用しているときに、

AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete);
ArrayAdapter<String> adapter  = new ArrayAdapter<String>(this, R.layout.custom_item, R.id.autoCompleteItem, StringArray);
textView.setAdapter(adapter);
于 2013-03-26T16:59:59.960 に答える