我的导航抽屉中有一个“ ExpandableListView”,并且单击侦听器不起作用,一旦打开导航抽屉并单击“ ExpandableListView”的任何父元素,它只会关闭抽屉。有人可以指导我我可能做错了什么。
ExpandableListView的源代码
private void populateExpandableList() {
prepareMenuData();
expandableListAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild, groupIcons, groupIconsSelected);
expandableListView.setAdapter(expandableListAdapter);
expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
switch (groupPosition) {
case 0:
...
break;
case 1:
...
break;
...
}
return false;
}
});
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
switch (groupPosition) {
case (2):
...
break;
}
return false;
}
});
public void prepareMenuData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
groupIcons = new ArrayList<Integer>();
groupIconsSelected = new ArrayList<Integer>();
groupIcons.add(R.drawable.cust_home);
...
listDataHeader.add("Home");
...
// Subcategories -- News
List<String> news = new ArrayList<String>();
...
listDataChild.put(listDataHeader.get(0), new ArrayList<String>());
listDataChild.put(listDataHeader.get(1), new ArrayList<String>());
listDataChild.put(listDataHeader.get(2), news);
...
}
onCreate内的源代码
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
View header = navigationView.getHeaderView(0);
userIv = header.findViewById(R.id.user_iv);
loginTv = header.findViewById(R.id.login_tv);
userNameTv = header.findViewById(R.id.username_tv);
emailTv = header.findViewById(R.id.email_tv);
navHeaderLl = header.findViewById(R.id.nav_header_ll);
setSupportActionBar(toolbar);
toolbar.setVisibility(View.GONE);
getSubcatFromServer();
setUpNavHeader();
populateExpandableList();
navigationView.setNavigationItemSelectedListener(this);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
toggle.getDrawerArrowDrawable().setColor(getResources().getColor(R.color.colorWhite));
drawer.addDrawerListener(toggle);
toggle.syncState();
}