Dynamically adding Views in a RecyclerView only to current item

前端 未结 8 2035
一向
一向 2020-12-20 12:08

I\'m dynamically adding Views to my items in a RecyclerView. These added Views should only be related to the item which they\'re added to, but I\'m having a pro

8条回答
  •  星月不相逢
    2020-12-20 12:48

    Save Information by tags for items with new child each time the Add newView operation occur. (In shared preference for example) Tag: create with item position onBindViewHolder.

    ...
    SharedPreference  sharedPref = getSharedPreference("text" + position, context);
    SharedPreference.Editor editor = sharedPref.edit();
    editor.putString("view", "ImageView");
    ...
    

    when load Adapter get this value and put default as null. I am not sure about its efficiency but i will work.

    ...
    String viewType = sharedPref.getString("view", null);
    //it will return ImageView 
    

    if you know some possible viewTypes for example always going to be ImageView & TextView so with some if statement it will be ok.

    if(viewType.equals("ImageVIew")){
    item(position).addView(new ImageVIew(context));
    }
    

    Good Luck

提交回复
热议问题