Create RecyclerView UI dynamically - Android
<p>I am working on an <strong>e-commerce</strong> App . Here I am working on <strong>Products Filtering</strong> . 
Here filters are dynamic, It means once filter page will display BRANDS and  PRICE then next time it can display BRANDS , PRICE , STYLES ..etc .
There may be many cases to filter products . </p>

<p>Application is receiving filters dynamically from Webservice .
So here I am creating filters dynamically using data received from the webservice . For this I am using RecyclerView to display dynamic filters 
.</p>

<p>Here is the code of RecyclerView where I am creating filters dynamically .</p>

<p><strong>onCreateViewHolder() :</strong></p>

<pre><code>  @Override
public FilterViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    LinearLayout topLayout = new LinearLayout(mContext);
    topLayout.setOrientation(LinearLayout.VERTICAL);

    if (filterItems != null) {
        for (int filterItemsCount = 0; filterItemsCount &lt; filterItems.size(); filterItemsCount++) {

            LinearLayout ll = new LinearLayout(mContext);
            ll.setOrientation(LinearLayout.VERTICAL);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            layoutParams.setMargins(10, 10, 10, 10);

            AFileterItem filterItem = filterItems.get(filterItemsCount);
            TextView textView = new TextView(mContext);
            textView.setText(filterItem.getFiletrLabel());
            ll.addView(textView);

            for (int i = 0; i &lt; filterItem.getList().size(); i++) {
                VlauesItem item1 = filterItem.getList().get(i);
                CheckBox cb = new CheckBox(mContext);
                cb.setId(i);
                cb.setText(item1.getValueItemLabel());

                cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        Toast.makeText(mContext, String.valueOf(isChecked), Toast.LENGTH_SHORT).show();
                    }
                });

                ll.addView(cb);
            }

            topLayout.addView(ll);
        }
    }else{
        topLayout.addView(null);
    }

    FilterViewHolder viewHolder = new FilterViewHolder(topLayout);
    return viewHolder;
}
</code></pre>

<blockquote>
  <p>Now , the problem is :</p>
</blockquote>

<p>When I create filters dynamically then RecyclerView creates same filter more than once .
    I want to know how should I manage above code so that I can eliminate this problem .</p>