Skip to content

Commit c9e42a0

Browse files
committed
Add utilities for bind view
1 parent fe38af7 commit c9e42a0

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

app/src/main/java/com/ramanaptr/sample/MainActivity.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class MainActivity : AppCompatActivity() {
3333
/**
3434
* turn "isSingleLayout" into "false" when you want to try multi layout stuff
3535
* */
36-
private var isSingleLayout = true
36+
private var isSingleLayout = false
3737

3838
override fun onCreate(savedInstanceState: Bundle?) {
3939
super.onCreate(savedInstanceState)
@@ -107,9 +107,10 @@ class MainActivity : AppCompatActivity() {
107107

108108
private fun exampleEzRecycleSingleLayout() {
109109

110-
// if you want use findViewById() you'll shouldn't cast the EzRecycleView
110+
// if you want use findViewById() you shouldn't cast the EzRecycleView
111111
// if you want use view binding you should to cast the object like the example below
112-
rvSample = binding.rvSample as EzRecyclerView<SampleData>
112+
// If you won't casting the object, you can use #EzRecyclerView.bind()
113+
rvSample = EzRecyclerView.bind(binding.rvSample)
113114

114115
// set class data
115116
rvSample.setData(SampleData::class.java)
@@ -145,9 +146,10 @@ class MainActivity : AppCompatActivity() {
145146

146147
private fun exampleEzRecycleMultipleLayout() {
147148

148-
// if you want use findViewById() you'll shouldn't cast the EzRecycleView
149+
// if you want use findViewById() you shouldn't cast the EzRecycleView
149150
// if you want use view binding you should to cast the object like the example below
150-
rvSample = binding.rvSample as EzRecyclerView<SampleData>
151+
// If you won't casting the object, you can use #EzRecyclerView.bind()
152+
rvSample = EzRecyclerView.bind(binding.rvSample)
151153

152154
// set class data
153155
rvSample.setData(SampleData::class.java)

ez-recyleview/src/main/java/com/ramanaptr/widget/EzRecyclerView.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public EzRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs, in
6464
initComponent();
6565
}
6666

67+
@SuppressWarnings(value = "unchecked")
68+
public static <EzRv extends EzRecyclerView<?>> EzRv bind(EzRecyclerView<?> view) {
69+
return (EzRv) view;
70+
}
71+
6772
private void initComponent() {
6873
if (baseAdapter == null) {
6974
baseAdapter = new BaseAdapter<>(ezMultipleLayout);
@@ -282,7 +287,7 @@ public void refresh() {
282287
/**
283288
* Use #reset() every re-start
284289
* Not recommend for first init
285-
* */
290+
*/
286291
public void reset() {
287292
this.limit = limitTemp;
288293
this.offset = offsetTemp;

0 commit comments

Comments
 (0)