4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Support Libraryを27.1.0に更新メモ

Last updated at Posted at 2018-03-08

はじめに

Support Library 27.1.0 がリリースされました。
Support Libraryを27.1.0に更新したときに行ったことをメモします。

RecyclerView.Adapter でのエラー

ビルドを行ったところ、以下のエラーが出た。

Error: Class '***RecyclerViewAdapter' is not abstract and does not implement abstract base class member @NonNull public abstract fun onCreateViewHolder(@NonNull p0: ViewGroup, p1: Int): ***RecyclerViewAdapter.ViewHolder defined in android.support.v7.widget.RecyclerView.Adapter

以下がnon-null型に変更されていたので対応しました。

  • RecyclerView.Adapter#onCreateViewHolder() の ViewGroup
  • RecyclerView.Adapter#onBindViewHolder() の RecyclerView.ViewHolder

//---------------------- Before ----------------------

override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
    // do something
}

override fun onBindViewHolder(holder: ViewHolder?, position: Int) {
    // do something
}

//---------------------- After ----------------------

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
    // do something
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    // do something
}

ViewModel を FragmentActivity / Fragment で渡す際

FragmentActivity and Fragment now implement ViewModelStoreOwner and can now be used with the ViewModelProvider constructors as an alternative to using ViewModelProviders.of()

FragmentActivity / Fragment に ViewModelStoreOwner が実装されていたそうなので、以下のように変えました。

***Fragment.kt

//---------------------- Before ----------------------

ViewModelProviders.of(this, factory).get(***ViewModel::class.java)

//---------------------- After ----------------------

ViewModelProvider(this, factory).get(***ViewModel::class.java)

RecyclerView の差分更新(今後)

ListAdapter for RecyclerView (along with AsyncListDiffer) make it easier to compute list diffs on a background thread. These can help your RecyclerView animate content changes automatically, with minimal work on the UI thread. They use DiffUtil under the hood.

ListAdapter を使って、RecyclerView の差分更新も行う予定です。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?