Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
80 views
in Technique[技术] by (71.8m points)

android - PagedListAdapter with AutoCompleteTextView

I wanted to implement an adapter for AutoCompleteTextView. I used PagedListAdapter to load paginated API response. However, when I tried to assign the adapter if shows an error "the adapter needs to implement ListAdapter". Is there any way to achieve this? My AutoCompleteTextView is

<com.google.android.material.textfield.TextInputLayout
                android:id="@+id/layout"
                style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense.ExposedDropdownMenu"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/activity_horizontal_margin_half"
                android:hint="@string/category"
                app:boxBackgroundColor="@color/edit_text_background"
                app:layout_constraintTop_toBottomOf="@+id/descriptionLayout">

                <androidx.appcompat.widget.AppCompatAutoCompleteTextView
                    android:id="@+id/editText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:cursorVisible="false"
                    android:focusableInTouchMode="false"
                    android:inputType="none"
                    android:maxLines="1" />

            </com.google.android.material.textfield.TextInputLayout>

Part of the adapter is

class CompanyAdapter :
    PagedListAdapter<Company, CompanyViewHolder>(object :
        DiffUtil.ItemCallback<Company>() {
        override fun areItemsTheSame(oldItem: Company, newItem: Company): Boolean {
            return oldItem.id == newItem.id
        }

        override fun areContentsTheSame(oldItem: Company, newItem: Company): Boolean {
            return oldItem.id == newItem.id
        }
    }) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CompanyViewHolder {
        val binding = ItemCompanyBinding.inflate(
            LayoutInflater.from(parent.context),
            parent,
            false
        )

        return CompanyViewHolder(binding)
    }

    override fun onBindViewHolder(holder: CompanyViewHolder, position: Int) {
        getItem(position)?.let { holder.bindPost(it) }
    }
}

The problem is in Fragment,

editText.adapter = companyAdapter

Any suggestion or solution? Thanks in Advance.

question from:https://stackoverflow.com/questions/65661554/pagedlistadapter-with-autocompletetextview

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...