Android仿天猫二级分类_二级分类ExpandableListView源代码
程序员文章站
2022-03-01 12:55:38
...
本Demo是一款有多种二级菜单的项目、有类似美团上的美食购物分类、有类似QQ分组的、有listview里面嵌套gridview的、几乎项目中个能用到的二级菜单这里都有
而且界面还是比较简洁的、很实用、又得直接可以在项目中应用、项目代码量也不是很多、而且都有详细的分层、项目中重要的部分也都有详细的注释、本项目采用UTF-8编码、运行效果如下
ListView 部分源代码
private void initView() { mainlist = (ListView) findViewById(R.id.classify_mainlist); morelist = (ListView) findViewById(R.id.classify_morelist); mainAdapter = new ClassifyMainAdapter(ListListActivity.this, mainList); mainAdapter.setSelectItem(0); mainlist.setAdapter(mainAdapter); mainlist.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { initAdapter(Model.MORELISTTXT[position]); mainAdapter.setSelectItem(position); mainAdapter.notifyDataSetChanged(); } }); mainlist.setChoiceMode(ListView.CHOICE_MODE_SINGLE); // 一定要设置这个属性,否则ListView不会刷新 initAdapter(Model.MORELISTTXT[0]); morelist.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { moreAdapter.setSelectItem(position); moreAdapter.notifyDataSetChanged(); } }); }
ExpandableListView部分代码
private void setListener() { expandableListView.setOnGroupClickListener(new OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { return false; } }); expandableListView.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { Toast.makeText(getApplicationContext(), child_text_array[groupPosition][childPosition], Toast.LENGTH_SHORT).show(); return false; } }); }
ExpandableGridView部分代码
private void setListener() { expandableGridView.setOnGroupClickListener(new OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { if (sign == -1) { // 展开被选的group expandableGridView.expandGroup(groupPosition); // 设置被选中的group置于顶端 expandableGridView.setSelectedGroup(groupPosition); sign = groupPosition; } else if (sign == groupPosition) { expandableGridView.collapseGroup(sign); sign = -1; } else { expandableGridView.collapseGroup(sign); // 展开被选的group expandableGridView.expandGroup(groupPosition); // 设置被选中的group置于顶端 expandableGridView.setSelectedGroup(groupPosition); sign = groupPosition; } return true; } }); }
最后给贴上Demo的源代码、希望对大家有用、有兴趣的哥们可以下载看看
源代码下载链接: http://dwtedx.com/download.html?bdkey=s/1o605NKI 密码: m9n6