Create CardView with dynamic custom list inside

馋奶兔 提交于 2019-12-12 04:06:52

问题


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.

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.

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


回答1:


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


来源:https://stackoverflow.com/questions/31203040/create-cardview-with-dynamic-custom-list-inside

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!