mirror of https://github.com/readrops/Readrops.git
Use viewbinding with custom views
This commit is contained in:
parent
2bc5438348
commit
442c257593
|
@ -2,26 +2,22 @@ package com.readrops.app.utils
|
|||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import com.readrops.app.R
|
||||
import com.readrops.app.databinding.EmptyListViewBinding
|
||||
|
||||
/**
|
||||
* A simple custom view to display a empty list message
|
||||
*/
|
||||
class EmptyListView(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) {
|
||||
|
||||
init {
|
||||
// no binding here, it makes the view rendering fail
|
||||
View.inflate(context, R.layout.empty_list_view, this)
|
||||
val imageView: ImageView = findViewById(R.id.empty_list_image)
|
||||
val textView: TextView = findViewById(R.id.empty_list_text_v)
|
||||
val binding: EmptyListViewBinding = EmptyListViewBinding.inflate(LayoutInflater.from(context), this, true)
|
||||
|
||||
init {
|
||||
val attributes = context.obtainStyledAttributes(attrs, R.styleable.EmptyListView)
|
||||
imageView.setImageDrawable(attributes.getDrawable(R.styleable.EmptyListView_image))
|
||||
textView.text = attributes.getString(R.styleable.EmptyListView_text)
|
||||
binding.emptyListImage.setImageDrawable(attributes.getDrawable(R.styleable.EmptyListView_image))
|
||||
binding.emptyListText.text = attributes.getString(R.styleable.EmptyListView_text)
|
||||
|
||||
attributes.recycle()
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
tools:src="@drawable/ic_rss_feed_grey" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/empty_list_text_v"
|
||||
android:id="@+id/empty_list_text"
|
||||
style="@style/TextAppearance.AppCompat.Large"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
Loading…
Reference in New Issue