CommonAdapter
????BaseAdapter?RecyclerView.Adapter?????????Adapter???
??
- ???????item
- item???type??????
- ???dataBinding???????
- ??ViewPager??????
- ??item?????????item?????
- ??item??????????????????
- ??item??????setViews()???????listener
- ?????ListView?adapter???recyclerView?adapter
- ???viewpager?notifyDataSetChanged()?????
- ???recyclerView?????????
RcvAdapterWrapper
? - ???recyclerView?????????
RcvAdapterWrapper
? - ???getCurrentPosition()??????????????item???
- ???getConvertedData(data, type)????item???????????
- ???item???Activity???????
- ??RecycleView????item????????????????
- ??Adapter??????item??????????
- ????????????????????adapter???notify??????databinding??
ObservableList
?
??
????????????????“??????QQ:515288905?”?UI???? ??
????????????????????????android???
????
1.??????build.gradle???JitPack??
repositories {
maven {
url "https://jitpack.io"
}
}
2.???????????
compile 'com.github.tianzhijiexian:CommonAdapter: Latest release(<-click it)'
???
compile 'com.github.tianzhijiexian:CommonAdapter:1.0.0'
??????
adapter?item???????????????
public interface AdapterItem<T> {
/**
* @return item?????layoutId
*/
@LayoutRes
int getLayoutResId();
/**
* ???views
*/
void bindViews(final View root);
/**
* ??view???
*/
void setViews();
/**
* ???????item???views
*
* @param model
??list???model
* @param position ??adapter??item???
*/
void handleData(T model, int position);
}
???
public class TextItem implements AdapterItem<DemoModel> {
@Override
public int getLayoutResId() {
return R.layout.demo_item_text;
}
TextView textView;
@Override
public void bindViews(View root) {
textView = (TextView) root.findViewById(R.id.textView);
}
@Override
public void setViews() {
}
@Override
public void handleData(DemoModel model, int position) {
textView.setText(model.content);
}
}
??ListView+GridView??????——CommonAdapter
???? CommonAdapter
????????
listView.setAdapter(new CommonAdapter<DemoModel>(list, 1) {
public AdapterItem<DemoModel> createItem(Object type) {
return new TextItem();
}
}
);
??RecyclerView??????——CommonRcvAdapter
???? CommonRcvAdapter
???????
mAdapter = new CommonRcvAdapter<DemoModel>(list) {
public AdapterItem createItem(Object type) {
return new TextItem();
}
}
;
??ViewPager??????——CommonPagerAdapter
???? CommonPagerAdapter
???????
viewPager.setAdapter(new CommonPagerAdapter<DemoModel>(list) {
public AdapterItem createItem(Object type) {
return new TextItem();
}
}
);
????RecyclerView?pool
???????? RecycledViewPool ???pool?
RecycledViewPool pool = new RecycledViewPool();
// ...
recyclerView.setRecycledViewPool(pool);
adapter.setTypePool(pool.getTypePool());
????
1. Adapter
???adapter??????????????????????adapter???????Item??????getView()????if-else?????? ?????adapter?????????8?????????????item????????????????????????item???????????????????????
2. AdapterItem
????????????????adapter?item???????????????RecyclerView?ViewHolder?????item??????????????????????????????
3. ??
????????????adapter??view????????view????????adapter??????????????????type??item?????????????????????adapter??mvp?p?????mvvm?m??????????????????m?p???????view?????????
???
Jack Tony: [email protected]
License
Copyright 2016-2019 Jack Tony 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.