A very simple multilayer package CommonAdapter. [中文文档]
| [ListView+GridView] | [RecyclerView] | [ViewPager] |
|---|---|---|
McAdapter(CommonAdapter) |
McRcvAdapter(CommonRcvAdapter) |
CommonPagerAdapter |
- In project build.gradle
repositories {
maven {
url "https://jitpack.io"
}
}
- In app build.gradle
implementation 'com.github.GitSmark:McAdapter:1.3.0'
- Get your AdapterItem
public class MyAdapterItem extends McAdapterItem<String> {
private TextView tv;
@Override
public int getLayoutResId() {
return R.layout.layout_item;
}
@Override
public void onBindViews(View root) {
tv = (TextView) root.findViewById(R.id.item);
}
@Override
public void onUpdateViews(String model) {
tv.setText(model);
}
@Override
public void onItemAction(int position) {
//tv.setOnClickListener(this);
}
}- Set your Adapter
listview.setAdapter(new McAdapter(this, data, McAdapterItem1.class)); //添加监听
listview.setAdapter(new McAdapter(list, McAdapterItem3.class, McAdapterItem4.class)); //多布局
listview.setAdapter(new CommonAdapter(data) {
@NonNull
@Override
public IAdapterItem onCreateItem(Object type) {
return new McAdapterItem2();
}
});
listview.setAdapter(new CommonAdapter<McEntity>(list, 2) {
@Override
public Object getItemType(McEntity obj) {
return obj.getItemType();
}
@NonNull
@Override
public IAdapterItem onCreateItem(Object type) {
switch (((int) type)) {
case 0:
return new McAdapterItem3();
case 1:
return new McAdapterItem4();
default:
throw new IllegalArgumentException("Illegal type");
}
}
});
Have problem? Just tweet me or send me an email.
Thanks originator tianzhijiexian and my friend chenyp.
Copyright 2016 huangxy@GitSmark
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.
