gabrielemariotti / cardslib

Android Library to build a UI Card
4.66k stars 1.19k forks source link

Data from setupInnerViewElements getting reset on scroll #545

Closed uzumakinaruto123 closed 8 years ago

uzumakinaruto123 commented 8 years ago

i am repeating cards like this

for (int i = 0; i < 50; i++) {
            CustomCard card = new CustomCard (getActivity(),"Header", i);
            if (i % 2 == 0){
                card.setBackgroundResourceId(R.drawable.even_back_draw);
            }else{
                card.setBackgroundResourceId(R.drawable.odd_back_draw);
            }

            cards.add(card);
 }

CustomCard


private class CustomCard extends Card{

        protected String mTitleHeader;
        protected int itemtype;

        public CustomCard (Context context, String titleHeader, int i) {
            super(context, R.layout.card_custom_layout);
            this.mTitleHeader=titleHeader;
            this.itemtype=i;
            init();
        }

        private void init(){

        }

        @Override
        public void setupInnerViewElements(ViewGroup parent, View view) {

            TextView text = (TextView) view.findViewById(R.id.offertextid);
            text.setText("Dynamic test item no :"+itemtype);

            ImageView oi = (ImageView) view.findViewById(R.id.itemimage);

           if (itemtype % 2 == 0){

               Glide.with(getActivity()).load(R.drawable.testimg).into(oi);
            }else{
                 oi.setVisibility(View.GONE);
            }

        }
    }

Images are set correctly for even elements as per the logic. But , On scroll all images are gone.

Looks like its because conditional checking i am doing inside setupInnerViewElements .

Any help is appreciated.

uzumakinaruto123 commented 8 years ago

Its solved ,

i had to do setVisibility(View.VISIBLE); too inside if

if (itemtype % 2 == 0){
               oi.setVisibility(View.VISIBLE);
               Glide.with(getActivity()).load(R.drawable.testimg).into(oi);
            }else{
                 oi.setVisibility(View.GONE);
            }