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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…