我的代码在大多数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?