RecyclerView 경동 분류 연동 효과 구현
5197 단어 MVP
Adapter–ParentAdapter
public class ParentAdapter extends BaseQuickAdapter {
public ParentAdapter(int layoutResId, @Nullable List data) {
super(layoutResId, data);
}
@Override
protected void convert(BaseViewHolder helper, final ParentBean.DataBean item) {
helper.setText(R.id.textone, item.getName());
helper.addOnClickListener(R.id.textone);
//
helper.setOnClickListener(R.id.textone, new View.OnClickListener() {
@Override
public void onClick(View view) {
//
mItemClick.onItem(item.getCid());
}
});
}
//
private ItemClick mItemClick;
//
public interface ItemClick {
void onItem(int data);
}
//
public void setitemClick(ItemClick mItemClick) {
this.mItemClick = mItemClick;
}
}
어댑터 – ChildName어댑터 중첩 하위 어댑터
public class ChildAdapter extends BaseQuickAdapter {
private TextView mTextView2;
private RecyclerView mRecyclerView;
public ChildAdapter(int layoutResId, @Nullable List data) {
super(layoutResId, data);
}
@Override
protected void convert(BaseViewHolder helper, ChildBean.DataBean item) {
helper.setText(R.id.twotext, item.getList().get(0).getName());
mRecyclerView = helper.itemView.findViewById(R.id.recythree);
GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 3);
mRecyclerView.setLayoutManager(gridLayoutManager);
ChildItemAdapter childItemAdapter = new ChildItemAdapter(R.layout.itemlayout, item
.getList());
mRecyclerView.setAdapter(childItemAdapter);
}
}
Adapter–ChildAdapter
public class ChildItemAdapter extends BaseQuickAdapter {
public ChildItemAdapter(int layoutResId, @Nullable List data) {
super(layoutResId, data);
}
@Override
protected void convert(BaseViewHolder helper, ChildBean.DataBean.ListBean item) {
helper.setText(R.id.textthree,item.getName() );
String images = item.getIcon();
Log.d(TAG, images + "+++images");
String[] split = images.split("\\|");
if (split.length > 0) {
Uri uri = Uri.parse(split[0]);
((ImageView) helper.getView(R.id.imagethree)).setImageURI(Uri.parse(split[0]));
Log.d(TAG, split[0] + "++++split[0]");
}
}
}
Activity
public class MainActivity extends AppCompatActivity implements DataCall {
@BindView(R.id.recyone)
RecyclerView recyone;
@BindView(R.id.recytwo)
RecyclerView recytwo;
private ParentPresenter parentPresenter;
private ParentAdapter parentAdapter;
private ChildPresenter childPresenter;
private int cidData = 1;
private List dataBeans;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
// P
parentPresenter = new ParentPresenter(this);
parentPresenter.showParent();
childPresenter = new ChildPresenter(this);
childPresenter.showParent(cidData);
}
@Override
public void showParent(ParentBean parentBean) {
dataBeans = parentBean.getData();
//
StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(1,
StaggeredGridLayoutManager.VERTICAL);
recyone.setLayoutManager(staggeredGridLayoutManager);
//
parentAdapter = new ParentAdapter(R.layout.parentitem, dataBeans);
recyone.setAdapter(parentAdapter);
parentAdapter.setitemClick(new ParentAdapter.ItemClick() {
@Override
public void onItem(int data) {
childPresenter.showParent(data);
}
});
}
@Override
public void showChild(ChildBean childBean) {
//
GridLayoutManager gridLayoutManager = new GridLayoutManager(MainActivity.this, 1);
recytwo.setLayoutManager(gridLayoutManager);
//
List childBeanData = childBean.getData();
ChildAdapter childAdapter = new ChildAdapter(R.layout.childview, childBeanData);
//
recytwo.setAdapter(childAdapter);
}
@Override
public void showError(String error) {
}
@Override
public Context CONTEXT() {
return this;
}
@Override
protected void onDestroy() {
super.onDestroy();
parentPresenter.onDestroy();
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
【Swift】MVP를 간단히 정리해 본다· Model, View, Presenter로 분할되는 GUI 아키텍처 · 데이터 동기화 방법에는 PassiveView와 SupervisingController의 두 가지가 있습니다. 먼저 PassiveView와 S...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.