0

我有一个代码在大多数 android 版本中运行了几年。

今天我意识到它不再适用于 API 26+

这是我的代码:

    mChapters = (ExpandableListView) findViewById(R.id.chapter_list);
    mChapters.setEmptyView(findViewById(R.id.empty));
    mChapterAdapter = new ChapterListViewAdapter(this);
    mChapters.setAdapter(mChapterAdapter);

    mChapters.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
            SectionTitle section = (SectionTitle) mChapterAdapter.getChild(groupPosition, childPosition);
            Intent intent = new Intent(getInstance(), getSectionTextActivityClass());
            intent.putExtra(AbstractSectionTextActivity.SECTION_ID, section.getId());
            startActivity(intent);
            return true;
        }

    });

    mChapters.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {

        @Override
        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
            SectionTitle section = (SectionTitle) mChapterAdapter.getGroup(groupPosition);
            if (section.getChildCount() == 0) {
                Intent intent = new Intent(AbstractMainActivity.this, getSectionTextActivityClass());
                intent.putExtra(AbstractSectionTextActivity.GROUP_ID, section.getId());
                startActivity(intent);
                return true;
            }
            return false;
        }
    });

我在 AVD - Nexus API 24,25,26,27 中对其进行了测试。对于 Nexus API <= 25,它工作正常 - 我可以点击组项目和子项目。从 Nexus API 26+ 开始,当我尝试单击组项和子项时没有任何反应。

有什么想法为什么或改变了 API?

4

0 回答 0