简介 English
1. Gradle 引用
compile 'com.biao.badapter:badapter:1.0.0'
compile 'com.biao.badapter:badapter-simple:1.0.0'
compile 'com.biao.badapter:badapter-databinding:1.0.0'
2. RecyclerView Adapter
目前就这一种创建方式
BAdapter adapter = BAdapter.builder()
.dataSource(dataSource)
.itemDelegate(itemDelegate)
.build();
3. 数据源
BDataSource<String> dataSource = new BDataSource<>();
4. Item代理
4.1 badapter 简单辅助类
BSimpleItemDelegate<String> itemDelegate = new BSimpleItemDelegate<String>() {
@Override protected View onCreateView(LayoutInflater inflater, ViewGroup parent) {
return inflater.inflate(R.layout.simple_text_1, parent, false);
}
@Override public void onBind(BSimpleViewHolder holder, String s) {
holder.getTextView(R.id.tv_content).setText(s);
}
};
4.2 badapter databinding辅助类
BDataBindingItemDelegate<SimpleText1Binding, String> itemDelegate =
new BDataBindingItemDelegate<SimpleText1Binding, String>() {
@Override
protected void onBind(BDataBindingViewHolder<SimpleText1Binding> holder, String s) {
holder.binding.setContent(s);
}
@Override
protected SimpleText1Binding onCreateBinding(LayoutInflater inflater, ViewGroup parent) {
return SimpleText1Binding.inflate(inflater, parent, false);
}
};
5. 点击事件
itemDelegate.dispatchViewClick(R.id.image)
.setOnItemClickListener(new OnItemClickListener<String>() {
@Override public void onItemClick(View view, int position, String s) {
switch (view.getId()) {
case R.id.image:
Toast.makeText(view.getContext(), "Image Click at " + s, Toast.LENGTH_SHORT).show();
break;
default:
Toast.makeText(view.getContext(), "Item Click at " + s, Toast.LENGTH_SHORT).show();
break;
}
}
});
License
Copyright 2016 BiaoWu
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.