可扩展列表视图给出了错误的组位置,只有在没有视图持有者的情

时间:2016-06-05 05:04:50

标签: android expandablelistview

我无法在不使用视图持有者模式的情况下继续操作,但因为我在每个列表中都运行倒计时,并且Expandablelistview在没有它的情况下变得不稳定。也许这是一个简单的修复。提前致谢。

@Override
public View getGroupView(int groupPosition, final boolean isExpanded, View convertView, final ViewGroup parent) {

    final ViewHolderItem viewHolder;

    if (convertView == null) {

        LayoutInflater infalInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.item_lobby, null);
        viewHolder = new ViewHolderItem();

        viewHolder.lobbyItemExpandIndicator = (ImageView) convertView.findViewById(R.id.lobbyItemExpandIndicator);
        viewHolder.draftEnding = (TextView) convertView.findViewById(R.id.lobbyDraftEnding);
        viewHolder.gameType = (TextView) convertView.findViewById(R.id.lobbyGameType);
        viewHolder.accepting = (TextView) convertView.findViewById(R.id.lobbyAccepting);
        viewHolder.gamesInDraft = (TextView) convertView.findViewById(R.id.lobbyGamesInDraft);

        //viewHolder.draftEnding.setText(groupPosition + "");


        convertView.setTag(viewHolder);
    } else {


        viewHolder = (ViewHolderItem) convertView.getTag();
    }

    final ContestItem contest =  mContests.get(groupPosition);

    //setCountdown(viewHolder, contest);


    viewHolder.gameType.setText(contest.getGameType());
    viewHolder.accepting.setText(contest.getAccepting());
    viewHolder.gamesInDraft.setText(contest.getNbaGamesAmnt());

    if (isExpanded) {
        viewHolder.lobbyItemExpandIndicator.setImageResource(R.drawable.w_dash);
    } else {
        viewHolder.lobbyItemExpandIndicator.setImageResource(R.drawable.w_down);
    }

    return convertView;
}

static class ViewHolderItem {
    TextView draftEnding;
    TextView gameType;
    TextView accepting;
    TextView gamesInDraft;
    ImageView lobbyItemExpandIndicator;
}

1 个答案:

答案 0 :(得分:0)

您应该将您的倒计时保留在组模型对象中而不是保留在视图中,每次都会重复使用视图。所以你必须在你的小组模型中保持倒计时,然后每次都进行视图恢复倒计时。

例如,如果您的显示数据是:

> dput(sample(d$Lat, 10))
structure(c(174L, 7L, 185L, 121L, 127L, 200L, 121L, 62L, 64L, 
191L), .Label = c("", "0°18'22<U+2033> N", "0°31'30<U+2033> S", 
"0°53'15<U+2033> N", "0°54'00<U+2033> S", "1°17'26<U+2033> N", 
"1°20'23<U+2033> S", "1°26'31<U+2033> N", "1°32'00<U+2033> N", 
"1°36'47<U+2033> N", "1°57'53<U+2033> S", "10°12'42<U+2033> N", 
"10°16'25<U+2033> N", "10°20'00<U+2033> S", "10°43'21<U+2033> N", 
"10°52'04<U+2033> N", "11°51'24<U+2033> N", "11°52'39<U+2033> S", 
"12°04'31<U+2033> N", "12°06'00<U+2033> N", "12°08'10<U+2033> N", 
"12°09'17<U+2033> N", "12°12'16<U+2033> S", "12°22'21<U+2033> N", 
"12°30'05<U+2033> N", "12°45'01<U+2033> N", "12°54'16<U+2033> N", 
"13°09'00<U+2033> N", "13°16'07<U+2033> S", "13°17'25<U+2033> N", 
"13°28'12<U+2033> N", "13°30'24<U+2033> N", "13°46'10<U+2033> S", 
"13°48'00<U+2033> N", "13°49'30<U+2033> N", "14°28'30<U+2033> N", 
"14°31'07<U+2033> S", "14°53'50<U+2033> N", "15°03'40<U+2033> N", 
"15°24'41<U+2033> N", "15°27'13<U+2033> N", "15°36'48<U+2033> N", 
"15°38'08<U+2033> N", "15°57'00<U+2033> N", "16°00'00<U+2033> N", 
"16°20'50<U+2033> N", "16°22'12<U+2033> N", "16°31'32<U+2033> S", 
"16°49'34<U+2033> N", "17°03'25<U+2033> S", "17°04'45<U+2033> N", 
"17°10'30<U+2033> N", "17°20'46<U+2033> N", "17°44'08<U+2033> N", 
"18°07'26<U+2033> S", "18°11'06<U+2033> N", "18°27'20<U+2033> S", 
"18°55'30<U+2033> S", "19°05'51<U+2033> N", "19°08'24<U+2033> N", 
"19°18'08<U+2033> S", "19°25'57<U+2033> N", "19°54'58<U+2033> S", 
"2°23'33<U+2033> N", "2°53'35<U+2033> N", "2°58'53<U+2033> S", 
"20°01'02<U+2033> N", "20°15'15<U+2033> N", "20°16'33<U+2033> S", 
"21°00'00<U+2033> N", "22°21'04<U+2033> N", "23°00'47<U+2033> N", 
"23°10'05<U+2033> S", "23°14'01<U+2033> S", "23°19'00<U+2033> S", 
"23°58'26<U+2033> N", "24°00'01<U+2033> N", "24°28'37<U+2033> N", 
"24°46'25<U+2033> N", "24°46'34<U+2033> S", "25°13'06<U+2033> N", 
"25°13'41<U+2033> N", "25°13'57<U+2033> N", "25°37'27<U+2033> N", 
"26°09'18<U+2033> N", "26°15'15<U+2033> N", "26°33'45<U+2033> S", 
"26°49'24<U+2033> N", "27°32'58<U+2033> N", "28°00'00<U+2033> N", 
"28°06'30<U+2033> N", "28°49'00<U+2033> S", "29°16'24<U+2033> N", 
"29°36'14<U+2033> S", "3°21'48<U+2033> S", "30°19'51<U+2033> N", 
"30°52'34<U+2033> N", "31°10'00<U+2033> N", "31°10'22<U+2033> N", 
"31°25'59<U+2033> N", "31°45'41<U+2033> S", "31°59'28<U+2033> N", 
"32°01'32<U+2033> N", "32°19'46<U+2033> N", "32°52'32<U+2033> S", 
"32°56'27<U+2033> N", "33°00'00<U+2033> N", "33°05'44<U+2033> N", 
"33°50'38<U+2033> N", "33°52'30<U+2033> N", "34°38'25<U+2033> N", 
"34°58'56<U+2033> N", "34°59'47<U+2033> S", "35°00'00<U+2033> N", 
"35°23'55<U+2033> N", "36°34'29<U+2033> N", "38°37'41<U+2033> N", 
"38°57'35<U+2033> N", "39°00'00<U+2033> N", "39°22'35<U+2033> N", 
"39°47'01<U+2033> N", "4°08'29<U+2033> N", "4°13'19<U+2033> N", 
"4°24'49<U+2033> N", "4°36'45<U+2033> N", "4°39'27<U+2033> S", 
"4°47'58<U+2033> S", "4°50'30<U+2033> N", "40°00'10<U+2033> N", 
"40°02'00<U+2033> N", "40°18'45<U+2033> N", "40°23'37<U+2033> N", 
"40°45'41<U+2033> N", "40°46'11<U+2033> N", "41°00'00<U+2033> N", 
"41°19'25<U+2033> N", "41°30'00<U+2033> S", "41°30'32<U+2033> N", 
"41°37'02<U+2033> N", "42°11'08<U+2033> N", "42°36'27<U+2033> N", 
"42°38'18<U+2033> N", "42°45'09<U+2033> N", "43°01'43<U+2033> N", 
"43°43'52<U+2033> N", "44°09'04<U+2033> S", "44°18'19<U+2033> N", 
"45°33'52<U+2033> N", "45°48'48<U+2033> N", "45°59'07<U+2033> N", 
"46°32'01<U+2033> N", "46°36'12<U+2033> N", "46°47'55<U+2033> N", 
"46°49'30<U+2033> N", "47°10'54<U+2033> N", "47°12'00<U+2033> N", 
"47°13'43<U+2033> N", "47°17'12<U+2033> N", "47°31'02<U+2033> N", 
"48°44'28<U+2033> N", "49°29'14<U+2033> N", "49°49'00<U+2033> N", 
"5°33'36<U+2033> N", "5°40'54<U+2033> S", "5°45'00<U+2033> N", 
"50°38'27<U+2033> N", "51°05'00<U+2033> N", "51°31'14<U+2033> N", 
"52°05'52<U+2033> N", "52°14'17<U+2033> N", "52°51'55<U+2033> N", 
"53°25'30<U+2033> N", "54°10'37<U+2033> S", "54°42'08<U+2033> N", 
"55°21'00<U+2033> N", "55°40'13<U+2033> N", "58°45'09<U+2033> N", 
"59°40'30<U+2033> N", "6°05'51<U+2033> N", "6°31'29<U+2033> S", 
"6°52'12<U+2033> S", "6°57'07<U+2033> N", "61°04'00<U+2033> N", 
"64°34'27<U+2033> N", "64°41'11<U+2033> N", "64°59'03<U+2033> N", 
"69°10'21<U+2033> S", "7°52'41<U+2033> N", "7°59'23<U+2033> N", 
"8°00'07<U+2033> N", "8°01'48<U+2033> N", "8°18'35<U+2033> N", 
"8°22'04<U+2033> N", "8°30'55<U+2033> S", "8°38'24<U+2033> N", 
"8°46'48<U+2033> N", "82°39'44<U+2033> N", "9°31'46<U+2033> N", 
"9°36'00<U+2033> N", "9°44'08<U+2033> S"), class = "factor")

然后你必须将你的倒计时保持在private HashMap<MenuCategoryModel, List<ChildCategoryModel>> mMainMenuExpandableList; 或者如果每个子项目都在MenuCategoryModel以及获取视图组或孩子(无论需要什么) - 还原倒计时。