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();
    }
}

좋은 웹페이지 즐겨찾기