使用内部的动态自定义列表创建CardView

问题描述:

我在我的应用程序中使用CardViews创建了一个RecyclerView.现在,我想在每个CardView中添加具有自定义布局的新的自定义视图列表(请参见示例Image).按下添加按钮时,应该在卡内插入此布局的新行.

I create a RecyclerView with CardViews in my app. Now I want to add inside each CardView a new List of custom Views, with a custom layout (see example Image). When the add button is pressed, there should be insert a new row of this layout inside the card.

我如何意识到这一点?在我读的互联网上,CardView内的ListView是不可能的,因为ListView是可滚动的,并且活动上不应有两个可滚动的View(这就是我发现的.)

How do I realize that? In the internet I readed, that a ListView inside the CardView is not possible, because a ListView is scrollable, and there should not be two scrollable Views on the activity (thats what I found..)

标记为红色的行是自定义行.

the red marked row is the custom row.

对于RecylcerView,我使用了ViewHolder,CustomAdapter等. 我需要里面的行吗?还是有更简单的方法?

for the RecylcerView I used the ViewHolder, CustomAdapter, etc. Do I need this for the rows inside to? or is there a simpler way?

我要做的是将Views的点击处理程序附加到您的ViewHolder.在此事件处理程序中,您可以委派某种演示者,该演示者将添加/删除/编辑持卡人中的View.

What I would do is attached a click handler to the Views is your ViewHolder. In this event handler you can delegate to a presenter of some sort that will add/remove/edit the View in the card holder.

 private class MyHolder extends ViewHolder 
        implements View.OnClickListener {
    ...

    public MyHolder(View itemView, MyPresenter presenter) {
        super(itemView);
        itemView.setOnClickListener(this);

        ...
    }

    @Override
    public void onClick(View v) {
        presenter.addRow(v);
    }
}