Introduction 中文版链接

1. Gradle Download

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. DataSource

BDataSource<String> dataSource = new BDataSource<>();

4. ItemDelegate

4.1 badapter-simple
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. onClickListener

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.