Too much boilerplate and effort to implement a list using RecyclerView. But, most of them can be omitted. This library will take care of the heavy part and leave you the easy part.
-
Data Binding
: We take advantage ofData Binding
to avoid to implement ViewHolder thenData Binding
is required.android { dataBinding { enabled true } }
-
Layout
<?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android"> <data> <variable name="onClick" type="android.view.View.OnClickListener"/> <variable name="item" type="vn.tiki.noadapter.sample.entity.User"/> </data> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@{item.name}" android:onClick="@{onClick}" /> </layout>
item
: - data for bindingonClick
: - set for views which you want to handleOnClickListener
-
Build Adapter
adapter = new OnlyAdapter.Builder() .layoutSelector(new LayoutSelector() { @Override public int layoutForType(int type) { return R.layout.item; } }) .onItemClickListener(new OnItemClickListener() { @Override public void onItemClick(View view, Object item, int position) { switch(view.getId()) { case R.id.text1: Log.d(TAG, "text1 is clicked"); break; case R.id.text2: Log.d(TAG, "text2 is clicked"); break; } } }) .build(); recyclerView.setAdapter(adapter);
See more in the sample
Download the latest JAR or grab via Gradle:
compile 'vn.tiki.noadapter:noadapter:1.0.0'
or Maven:
<dependency>
<groupId>vn.tiki.noadapter</groupId>
<artifactId>noadapter</artifactId>
<version>1.0.0</version>
</dependency>
Snapshots of the development version are available in Sonatype's snapshots
repository.
No specific
Copyright 2016 Tiki Corp
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.