@@ -29,6 +29,7 @@ class StatusLayout {
2929
3030 private var inflater: LayoutInflater ? = null
3131 private var statusLayoutHelper: StatusLayoutHelper ? = null
32+ private var statusClickListener: StatusClickListener ? = null
3233
3334 private fun inflater (@LayoutRes resource : Int ): View {
3435 if (null == inflater) {
@@ -52,6 +53,7 @@ class StatusLayout {
5253 this .errorLayoutID = builder.errorLayoutID
5354 this .errorText = builder.errorText
5455
56+ this .statusClickListener = builder.statusClickListener
5557 this .statusLayoutHelper = StatusLayoutHelper (contentLayout)
5658 }
5759
@@ -96,8 +98,18 @@ class StatusLayout {
9698 val emptyTextView = emptyLayout!! .findViewById<TextView >(R .id.tv_status_empty)
9799 emptyTextView?.text = emptyText
98100 }
99- }
101+ if (statusClickListener == null ) { // 防止出错
102+ return
103+ }
100104
105+ val view = emptyLayout!! .findViewById<TextView >(R .id.tv_click_empty)
106+ if (null == view) { // 防止自定义布局ID出错
107+ return
108+ }
109+ view.setOnClickListener {
110+ statusClickListener!! .onEmptyClick(it)
111+ }
112+ }
101113
102114 /* *
103115 * 显示错误布局
@@ -115,6 +127,17 @@ class StatusLayout {
115127 val errorTextView = errorLayout!! .findViewById<TextView >(R .id.tv_status_error)
116128 errorTextView?.text = errorText
117129 }
130+ if (statusClickListener == null ) { // 防止出错
131+ return
132+ }
133+
134+ val view = errorLayout!! .findViewById<TextView >(R .id.tv_click_error)
135+ if (null == view) { // 防止自定义布局ID出错
136+ return
137+ }
138+ view.setOnClickListener {
139+ statusClickListener!! .onErrorClick(it)
140+ }
118141 }
119142
120143 class Builder {
@@ -132,12 +155,13 @@ class StatusLayout {
132155 var emptyText: String = " "
133156 var errorText: String = " "
134157
158+ lateinit var statusClickListener: StatusClickListener
159+
135160 constructor (contentLayout: View ) {
136161 this .contentLayout = contentLayout
137162 this .loadingLayoutID = R .layout.layout_loading
138163 this .emptyLayoutID = R .layout.layout_empty
139164 this .errorLayoutID = R .layout.layout_error
140-
141165 }
142166
143167 fun build (): StatusLayout {
@@ -204,6 +228,9 @@ class StatusLayout {
204228 return this
205229 }
206230
207-
231+ fun setStatusClickListener (listener : StatusClickListener ): Builder {
232+ this .statusClickListener = listener
233+ return this
234+ }
208235 }
209236}
0 commit comments