Skip to content Skip to sidebar Skip to footer

Setting Countdown Timer In Expandablelistview - Recycling Issue

Okay, I previously wrote this question, but have narrowed the problem down since then so decided to rewrite it. What I am trying to do is set a Countdown Timer in each group in Exp

Solution 1:

I repeat one more time, you again get item from viewholder, view holder - read this two words and try to understand them:

1) viewholder is for hold views, this mean it's for to hold results for such operations as findViewById (this is heavy operation for app).

2) viewholder reuses views, DON'T keep information that is related to item in list, it's only for views! Coz if you store info in next your scroll it viewholder can contain information from another item.

3) all data information, including countdowns must be hold in item model, right in your hashmap and must be restored from it in onBindViewholder only in this way is the right way.

here is sample how to do it from my code:

in adapter you define:

privateHashMap<CategoryModel, List<CategoryModel>> mMainMenuExpandableList; // This is your categories;privateList<CategoryModel> mMainMenuKeysList; // This is your keys to be easier already in separated list;

in constructor you set this values:

publicCategoriesExpandableListAdapter(HashMap<CategoryModel, List<CategoryModel>> hashMap, List<CategoryModel> keyList){
    mMainMenuExpandableList = hashMap;
    mMainMenuKeysList = keyList;
}

then you override getGroup and getChild:

@Override
public Object getGroup(int groupPosition) {
    return mMainMenuKeysList.get(groupPosition);
}

@Override
public Object getChild(int groupPosition, int childPosition) {
    return mMainMenuExpandableList.get(mMainMenuKeysList.get(groupPosition)).get(childPosition);
}

then in getGroupView:

finalCategoryModelgroupObject= (CategoryModel) getGroup(groupPosition);

in getChildView you can get both objects to act:

CategoryModelgroupObject= (CategoryModel) getGroup(groupPosition);
CategoryModelchildObject= (CategoryModel) getChild(groupPosition,childPosition);

and now when you got proper object from hash for category you can get from that object your countdowns and display them.

Hope this will help, Have a nice day :)

Post a Comment for "Setting Countdown Timer In Expandablelistview - Recycling Issue"