gpt4 book ai didi

AutoCompleteTextView 的 Android 自定义布局

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:20:17 26 4
gpt4 key购买 nike

我可能在这里遗漏了一些简单的东西,但我有一个 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);

最佳答案

我的猜测是您的 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);

关于AutoCompleteTextView 的 Android 自定义布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15641900/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com