這篇文章主要介紹Android如何實(shí)現(xiàn)多級(jí)樹(shù)形選擇列表,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
創(chuàng)新互聯(lián)公司成立以來(lái)不斷整合自身及行業(yè)資源、不斷突破觀念以使企業(yè)策略得到完善和成熟,建立了一套“以技術(shù)為基點(diǎn),以客戶需求中心、市場(chǎng)為導(dǎo)向”的快速反應(yīng)體系。對(duì)公司的主營(yíng)項(xiàng)目,如中高端企業(yè)網(wǎng)站企劃 / 設(shè)計(jì)、行業(yè) / 企業(yè)門戶設(shè)計(jì)推廣、行業(yè)門戶平臺(tái)運(yùn)營(yíng)、成都APP應(yīng)用開(kāi)發(fā)、手機(jī)網(wǎng)站制作、微信網(wǎng)站制作、軟件開(kāi)發(fā)、綿陽(yáng)服務(wù)器托管等實(shí)行標(biāo)準(zhǔn)化操作,讓客戶可以直觀的預(yù)知到從創(chuàng)新互聯(lián)公司可以獲得的服務(wù)效果。
項(xiàng)目中有多個(gè)地方要用到多級(jí)列表的菜單,最開(kāi)始我用的是ExpandableListView,但問(wèn)題是ExpandableListView只支持兩級(jí)列表,于是我就用ExpandableListView嵌套ExpandableListView,但非常麻煩,而且關(guān)鍵的是具體分幾級(jí)是不確定的,也就是可能一級(jí),可能多級(jí),這要是五六級(jí)嵌套ListView,于是我就去學(xué)習(xí)鴻洋大神之前寫的一篇關(guān)于實(shí)現(xiàn)Android多級(jí)樹(shù)形列表的文章,實(shí)現(xiàn)很巧妙,使用一個(gè)ListView就可以實(shí)現(xiàn)多級(jí)列表效果,我做了部分修改,功能順利實(shí)現(xiàn)。
1.定義節(jié)點(diǎn)實(shí)體類:
package com.xiaoyehai.multileveltreelist.treelist; import java.util.ArrayList; import java.util.List; /** * 節(jié)點(diǎn)實(shí)體類 * Created by xiaoyehai on 2018/7/11 0011. */ public class Node{ /** * 當(dāng)前節(jié)點(diǎn)id */ private String id; /** * 父節(jié)點(diǎn)id */ private String pid; /** * 節(jié)點(diǎn)數(shù)據(jù)實(shí)體類 */ private T data; /** * 設(shè)置開(kāi)啟 關(guān)閉的圖片 */ public int iconExpand = -1, iconNoExpand = -1; /** * 節(jié)點(diǎn)名稱 */ private String name; /** * 當(dāng)前的級(jí)別 */ private int level; /** * 是否展開(kāi) */ private boolean isExpand = false; private int icon = -1; /** * 下一級(jí)的子Node */ private List children = new ArrayList<>(); /** * 父Node */ private Node parent; /** * 是否被checked選中 */ private boolean isChecked; public Node() { } public Node(String id, String pid, String name) { this.id = id; this.pid = pid; this.name = name; } public Node(String id, String pid, T data, String name) { this.id = id; this.pid = pid; this.data = data; this.name = name; } /** * 是否為根節(jié)點(diǎn) * * @return */ public boolean isRootNode() { return parent == null; } /** * 判斷父節(jié)點(diǎn)是否展開(kāi) * * @return */ public boolean isParentExpand() { if (parent == null) return false; return parent.isExpand(); } /** * 是否是葉子節(jié)點(diǎn) * * @return */ public boolean isLeaf() { return children.size() == 0; } /** * 獲取當(dāng)前的級(jí)別level */ public int getLevel() { return parent == null ? 0 : parent.getLevel() + 1; } /** * 設(shè)置展開(kāi) * * @param isExpand */ public void setExpand(boolean isExpand) { this.isExpand = isExpand; if (!isExpand) { for (Node node : children) { node.setExpand(isExpand); } } } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getPid() { return pid; } public void setPid(String pid) { this.pid = pid; } public T getData() { return data; } public void setData(T data) { this.data = data; } public int getIconExpand() { return iconExpand; } public void setIconExpand(int iconExpand) { this.iconExpand = iconExpand; } public int getIconNoExpand() { return iconNoExpand; } public void setIconNoExpand(int iconNoExpand) { this.iconNoExpand = iconNoExpand; } public String getName() { return name; } public void setName(String name) { this.name = name; } public void setLevel(int level) { this.level = level; } public boolean isExpand() { return isExpand; } public int getIcon() { return icon; } public void setIcon(int icon) { this.icon = icon; } public List getChildren() { return children; } public void setChildren(List children) { this.children = children; } public Node getParent() { return parent; } public void setParent(Node parent) { this.parent = parent; } public boolean isChecked() { return isChecked; } public void setChecked(boolean checked) { isChecked = checked; } }
2.定義每個(gè)節(jié)點(diǎn)數(shù)據(jù)的實(shí)體類
因?yàn)轫?xiàng)目中多個(gè)地方用到樹(shù)形菜單,而且數(shù)據(jù)都不一樣,每個(gè)節(jié)點(diǎn)數(shù)據(jù)都比較復(fù)雜,所以我單獨(dú)封裝出一個(gè)類,要是數(shù)據(jù)和簡(jiǎn)單,這步可以不用,直接用Node類。
例如:
/** * 每個(gè)節(jié)點(diǎn)的具體數(shù)據(jù) * Created by xiaoyehai on 2018/7/11 0011. */ public class NodeData { private String name; public NodeData() { } public NodeData(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
3.TreeHelper
package com.xiaoyehai.multileveltreelist.treelist; import java.util.ArrayList; import java.util.List; /** * Created by xiaoyehai on 2018/7/11 0011. */ public class TreeHelper { /** * 傳入node 返回排序后的Node * 拿到用戶傳入的數(shù)據(jù),轉(zhuǎn)化為L(zhǎng)ist以及設(shè)置Node間關(guān)系,然后根節(jié)點(diǎn),從根往下遍歷進(jìn)行排序; * * @param datas * @param defaultExpandLevel 默認(rèn)顯示 * @return * @throws IllegalArgumentException * @throws IllegalAccessException */ public static List getSortedNodes(List datas, int defaultExpandLevel) { List result = new ArrayList (); // 設(shè)置Node間父子關(guān)系 List nodes = convetData2Node(datas); // 拿到根節(jié)點(diǎn) List rootNodes = getRootNodes(nodes); // 排序以及設(shè)置Node間關(guān)系 for (Node node : rootNodes) { addNode(result, node, defaultExpandLevel, 1); } return result; } /** * 過(guò)濾出所有可見(jiàn)的Node * 過(guò)濾Node的代碼很簡(jiǎn)單,遍歷所有的Node,只要是根節(jié)點(diǎn)或者父節(jié)點(diǎn)是展開(kāi)狀態(tài)就添加返回 * * @param nodes * @return */ public static List filterVisibleNode(List nodes) { List result = new ArrayList (); for (Node node : nodes) { // 如果為跟節(jié)點(diǎn),或者上層目錄為展開(kāi)狀態(tài) if (node.isRootNode() || node.isParentExpand()) { setNodeIcon(node); result.add(node); } } return result; } /** * 將我們的數(shù)據(jù)轉(zhuǎn)化為樹(shù)的節(jié)點(diǎn) * 設(shè)置Node間,父子關(guān)系;讓每?jī)蓚€(gè)節(jié)點(diǎn)都比較一次,即可設(shè)置其中的關(guān)系 */ private static List convetData2Node(List nodes) { for (int i = 0; i < nodes.size(); i++) { Node n = nodes.get(i); for (int j = i + 1; j < nodes.size(); j++) { Node m = nodes.get(j); if (m.getPid() instanceof String) { if (m.getPid().equals(n.getId())) { //n時(shí)m的父節(jié)點(diǎn) n.getChildren().add(m); m.setParent(n); } else if (m.getId().equals(n.getPid())) { //m時(shí)n的父節(jié)點(diǎn) m.getChildren().add(n); n.setParent(m); } } else { if (m.getPid() == n.getId()) { n.getChildren().add(m); m.setParent(n); } else if (m.getId() == n.getPid()) { m.getChildren().add(n); n.setParent(m); } } } } return nodes; } /** * 獲得根節(jié)點(diǎn) * * @param nodes * @return */ private static List getRootNodes(List nodes) { List root = new ArrayList (); for (Node node : nodes) { if (node.isRootNode()) root.add(node); } return root; } /** * 把一個(gè)節(jié)點(diǎn)上的所有的內(nèi)容都掛上去 * 通過(guò)遞歸的方式,把一個(gè)節(jié)點(diǎn)上的所有的子節(jié)點(diǎn)等都按順序放入 */ private static void addNode(List nodes, Node node, int defaultExpandLeval, int currentLevel) { nodes.add(node); if (defaultExpandLeval >= currentLevel) { node.setExpand(true); } if (node.isLeaf()) return; for (int i = 0; i < node.getChildren().size(); i++) { addNode(nodes, node.getChildren().get(i), defaultExpandLeval, currentLevel + 1); } } /** * 設(shè)置節(jié)點(diǎn)的圖標(biāo) * * @param node */ private static void setNodeIcon(Node node) { if (node.getChildren().size() > 0 && node.isExpand()) { node.setIcon(node.iconExpand); } else if (node.getChildren().size() > 0 && !node.isExpand()) { node.setIcon(node.iconNoExpand); } else { node.setIcon(-1); } } }
4.TreeListViewAdapter
對(duì)于ListView的適配器,需要繼承自TreeListViewAdapter,如
package com.xiaoyehai.multileveltreelist.treelist; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.ListView; import java.util.ArrayList; import java.util.List; /** * Created by xiaoyehai on 2018/7/11 0011. */ public abstract class TreeListViewAdapter extends BaseAdapter { protected Context mContext; /** * 默認(rèn)不展開(kāi) */ private int defaultExpandLevel = 0; /** * 展開(kāi)與關(guān)閉的圖片 */ private int iconExpand = -1, iconNoExpand = -1; /** * 存儲(chǔ)所有的Node */ protected ListmAllNodes = new ArrayList<>(); protected LayoutInflater mInflater; /** * 存儲(chǔ)所有可見(jiàn)的Node */ protected List mNodes = new ArrayList<>(); /** * 點(diǎn)擊的回調(diào)接口 */ private OnTreeNodeClickListener onTreeNodeClickListener; public void setOnTreeNodeClickListener(OnTreeNodeClickListener onTreeNodeClickListener) { this.onTreeNodeClickListener = onTreeNodeClickListener; } public TreeListViewAdapter(ListView listView, Context context, List datas, int defaultExpandLevel, int iconExpand, int iconNoExpand) { this.mContext = context; this.defaultExpandLevel = defaultExpandLevel; this.iconExpand = iconExpand; this.iconNoExpand = iconNoExpand; for (Node node : datas) { node.getChildren().clear(); node.setIconExpand(iconExpand); node.setIconNoExpand(iconNoExpand); } /** * 對(duì)所有的Node進(jìn)行排序 */ mAllNodes = TreeHelper.getSortedNodes(datas, defaultExpandLevel); /** * 過(guò)濾出可見(jiàn)的Node */ mNodes = TreeHelper.filterVisibleNode(mAllNodes); mInflater = LayoutInflater.from(context); /** * 設(shè)置節(jié)點(diǎn)點(diǎn)擊時(shí),可以展開(kāi)以及關(guān)閉;并且將ItemClick事件繼續(xù)往外公布 */ listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView> parent, View view, int position, long id) { expandOrCollapse(position); if (onTreeNodeClickListener != null) { onTreeNodeClickListener.onClick(mNodes.get(position), position); } } }); } /** * @param listView * @param context * @param datas * @param defaultExpandLevel 默認(rèn)展開(kāi)幾級(jí)樹(shù) */ public TreeListViewAdapter(ListView listView, Context context, List datas, int defaultExpandLevel) { this(listView, context, datas, defaultExpandLevel, -1, -1); } /** * 相應(yīng)ListView的點(diǎn)擊事件 展開(kāi)或關(guān)閉某節(jié)點(diǎn) * * @param position */ public void expandOrCollapse(int position) { Node n = mNodes.get(position); if (n != null) {// 排除傳入?yún)?shù)錯(cuò)誤異常 if (!n.isLeaf()) { n.setExpand(!n.isExpand()); //獲取所有可見(jiàn)的Node mNodes = TreeHelper.filterVisibleNode(mAllNodes); notifyDataSetChanged();// 刷新視圖 } } } @Override public int getCount() { return mNodes.size(); } @Override public Object getItem(int position) { return mNodes.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { Node node = mNodes.get(position); convertView = getConvertView(node, position, convertView, parent); // 設(shè)置內(nèi)邊距 convertView.setPadding(node.getLevel() * 50, 12, 12, 12); return convertView; } /** * 獲取排序后所有節(jié)點(diǎn) * * @return */ public List getAllNodes() { if (mAllNodes == null) mAllNodes = new ArrayList (); return mAllNodes; } /** * 獲取所有選中節(jié)點(diǎn) * * @return */ public List getSelectedNode() { List checks = new ArrayList (); for (int i = 0; i < mAllNodes.size(); i++) { Node n = mAllNodes.get(i); if (n.isChecked()) { checks.add(n); } } return checks; } /** * 設(shè)置多選 * * @param node * @param checked */ protected void setChecked(final Node node, boolean checked) { node.setChecked(checked); setChildChecked(node, checked); if (node.getParent() != null) setNodeParentChecked(node.getParent(), checked); notifyDataSetChanged(); } /** * 設(shè)置是否選中 * * @param node * @param checked */ public void setChildChecked(Node node, boolean checked) { if (!node.isLeaf()) { node.setChecked(checked); for (Node childrenNode : node.getChildren()) { setChildChecked(childrenNode, checked); } } else { node.setChecked(checked); } } private void setNodeParentChecked(Node node, boolean checked) { if (checked) { node.setChecked(checked); if (node.getParent() != null) setNodeParentChecked(node.getParent(), checked); } else { List childrens = node.getChildren(); boolean isChecked = false; for (Node children : childrens) { if (children.isChecked()) { isChecked = true; } } //如果所有自節(jié)點(diǎn)都沒(méi)有被選中 父節(jié)點(diǎn)也不選中 if (!isChecked) { node.setChecked(checked); } if (node.getParent() != null) setNodeParentChecked(node.getParent(), checked); } } /** * 清除掉之前數(shù)據(jù)并刷新 重新添加 * * @param mlists * @param defaultExpandLevel 默認(rèn)展開(kāi)幾級(jí)列表 */ public void addDataAll(List mlists, int defaultExpandLevel) { mAllNodes.clear(); addData(-1, mlists, defaultExpandLevel); } /** * 在指定位置添加數(shù)據(jù)并刷新 可指定刷新后顯示層級(jí) * * @param index * @param mlists * @param defaultExpandLevel 默認(rèn)展開(kāi)幾級(jí)列表 */ public void addData(int index, List mlists, int defaultExpandLevel) { this.defaultExpandLevel = defaultExpandLevel; notifyData(index, mlists); } /** * 在指定位置添加數(shù)據(jù)并刷新 * * @param index * @param mlists */ public void addData(int index, List mlists) { notifyData(index, mlists); } /** * 添加數(shù)據(jù)并刷新 * * @param mlists */ public void addData(List mlists) { addData(mlists, defaultExpandLevel); } /** * 添加數(shù)據(jù)并刷新 可指定刷新后顯示層級(jí) * * @param mlists * @param defaultExpandLevel */ public void addData(List mlists, int defaultExpandLevel) { this.defaultExpandLevel = defaultExpandLevel; notifyData(-1, mlists); } /** * 添加數(shù)據(jù)并刷新 * * @param node */ public void addData(Node node) { addData(node, defaultExpandLevel); } /** * 添加數(shù)據(jù)并刷新 可指定刷新后顯示層級(jí) * * @param node * @param defaultExpandLevel */ public void addData(Node node, int defaultExpandLevel) { List nodes = new ArrayList<>(); nodes.add(node); this.defaultExpandLevel = defaultExpandLevel; notifyData(-1, nodes); } /** * 刷新數(shù)據(jù) * * @param index * @param mListNodes */ public void notifyData(int index, List mListNodes) { for (int i = 0; i < mListNodes.size(); i++) { Node node = mListNodes.get(i); node.getChildren().clear(); node.iconExpand = iconExpand; node.iconNoExpand = iconNoExpand; } for (int i = 0; i < mAllNodes.size(); i++) { Node node = mAllNodes.get(i); node.getChildren().clear(); //node.isNewAdd = false; } if (index != -1) { mAllNodes.addAll(index, mListNodes); } else { mAllNodes.addAll(mListNodes); } /** * 對(duì)所有的Node進(jìn)行排序 */ mAllNodes = TreeHelper.getSortedNodes(mAllNodes, defaultExpandLevel); /** * 過(guò)濾出可見(jiàn)的Node */ mNodes = TreeHelper.filterVisibleNode(mAllNodes); //刷新數(shù)據(jù) notifyDataSetChanged(); } public abstract View getConvertView(Node node, int position, View convertView, ViewGroup parent); }
5.接口回調(diào):
選中狀態(tài)改變的回調(diào):
package com.xiaoyehai.multileveltreelist.treelist; /** * Created by xiaoyehai on 2018/7/12 0012. */ public interface OnTreeNodeCheckedChangeListener { void onCheckChange(Node node, int position, boolean isChecked); }
條目點(diǎn)擊的回調(diào):
package com.xiaoyehai.multileveltreelist.treelist; /** * Created by xiaoyehai on 2018-07-12. */ public interface OnTreeNodeClickListener { void onClick(Node node, int position); }
6.使用:
布局文件:
Activity:
public class ListViewActivity extends AppCompatActivity { private ListView mListView; private ListdataList = new ArrayList<>(); private ListViewAdapter mAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list_view); mListView = (ListView) findViewById(R.id.listview); initData(); //第一個(gè)參數(shù) ListView //第二個(gè)參數(shù) 上下文 //第三個(gè)參數(shù) 數(shù)據(jù)集 //第四個(gè)參數(shù) 默認(rèn)展開(kāi)層級(jí)數(shù) 0為不展開(kāi) //第五個(gè)參數(shù) 展開(kāi)的圖標(biāo) //第六個(gè)參數(shù) 閉合的圖標(biāo) mAdapter = new ListViewAdapter(mListView, this, dataList, 0, R.drawable.zoomout_yzs, R.drawable.zoomin_yzs); mListView.setAdapter(mAdapter); //獲取所有節(jié)點(diǎn) final List allNodes = mAdapter.getAllNodes(); for (Node allNode : allNodes) { //Log.e("xyh", "onCreate: " + allNode.getName()); } //選中狀態(tài)監(jiān)聽(tīng) mAdapter.setCheckedChangeListener(new OnTreeNodeCheckedChangeListener() { @Override public void onCheckChange(Node node, int position, boolean isChecked) { //獲取所有選中節(jié)點(diǎn) List selectedNode = mAdapter.getSelectedNode(); for (Node n : selectedNode) { Log.e("xyh", "onCheckChange: " + n.getName()); } } }); } /** * 模擬數(shù)據(jù),實(shí)際開(kāi)發(fā)中對(duì)返回的json數(shù)據(jù)進(jìn)行封裝 */ private void initData() { //根節(jié)點(diǎn) Node node = new Node<>("0", "-1", "根節(jié)點(diǎn)1"); dataList.add(node); dataList.add(new Node<>("1", "-1", "根節(jié)點(diǎn)2")); dataList.add(new Node<>("2", "-1", "根節(jié)點(diǎn)3")); //根節(jié)點(diǎn)1的二級(jí)節(jié)點(diǎn) dataList.add(new Node<>("3", "0", "二級(jí)節(jié)點(diǎn)")); dataList.add(new Node<>("4", "0", "二級(jí)節(jié)點(diǎn)")); dataList.add(new Node<>("5", "0", "二級(jí)節(jié)點(diǎn)")); //根節(jié)點(diǎn)2的二級(jí)節(jié)點(diǎn) dataList.add(new Node<>("6", "1", "二級(jí)節(jié)點(diǎn)")); dataList.add(new Node<>("7", "1", "二級(jí)節(jié)點(diǎn)")); dataList.add(new Node<>("8", "1", "二級(jí)節(jié)點(diǎn)")); //根節(jié)點(diǎn)3的二級(jí)節(jié)點(diǎn) dataList.add(new Node<>("9", "2", "二級(jí)節(jié)點(diǎn)")); dataList.add(new Node<>("10", "2", "二級(jí)節(jié)點(diǎn)")); dataList.add(new Node<>("11", "2", "二級(jí)節(jié)點(diǎn)")); //三級(jí)節(jié)點(diǎn) dataList.add(new Node<>("12", "3", "三級(jí)節(jié)點(diǎn)")); dataList.add(new Node<>("13", "3", "三級(jí)節(jié)點(diǎn)")); dataList.add(new Node<>("14", "3", "三級(jí)節(jié)點(diǎn)")); dataList.add(new Node<>("15", "4", "三級(jí)節(jié)點(diǎn)")); dataList.add(new Node<>("16", "4", "三級(jí)節(jié)點(diǎn)")); dataList.add(new Node<>("17", "4", "三級(jí)節(jié)點(diǎn)")); dataList.add(new Node<>("18", "5", "三級(jí)節(jié)點(diǎn)")); dataList.add(new Node<>("19", "5", "三級(jí)節(jié)點(diǎn)")); dataList.add(new Node<>("20", "5", "三級(jí)節(jié)點(diǎn)")); //四級(jí)節(jié)點(diǎn) dataList.add(new Node<>("21", "12", "四級(jí)節(jié)點(diǎn)")); //... //可以有無(wú)線多層級(jí) } }
adapter:
package com.xiaoyehai.multileveltreelist.adapter; import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import com.xiaoyehai.multileveltreelist.R; import com.xiaoyehai.multileveltreelist.treelist.OnTreeNodeCheckedChangeListener; import com.xiaoyehai.multileveltreelist.treelist.TreeListViewAdapter; import com.xiaoyehai.multileveltreelist.treelist.Node; import java.util.List; /** * Created by xiaoyehai on 2018/7/12 0012. */ public class ListViewAdapter extends TreeListViewAdapter { private OnTreeNodeCheckedChangeListener checkedChangeListener; public void setCheckedChangeListener(OnTreeNodeCheckedChangeListener checkedChangeListener) { this.checkedChangeListener = checkedChangeListener; } public ListViewAdapter(ListView listView, Context context, Listdatas, int defaultExpandLevel, int iconExpand, int iconNoExpand) { super(listView, context, datas, defaultExpandLevel, iconExpand, iconNoExpand); } @Override public View getConvertView(final Node node, final int position, View convertView, ViewGroup parent) { final ViewHolder holder; if (convertView == null) { convertView = View.inflate(mContext, R.layout.item, null); holder = new ViewHolder(convertView); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.tvName.setText(node.getName()); if (node.getIcon() == -1) { holder.ivExpand.setVisibility(View.INVISIBLE); } else { holder.ivExpand.setVisibility(View.VISIBLE); holder.ivExpand.setImageResource(node.getIcon()); } holder.checkBox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setChecked(node, holder.checkBox.isChecked()); if (checkedChangeListener != null) { checkedChangeListener.onCheckChange(node, position,holder.checkBox.isChecked()); } } }); if (node.isChecked()) { holder.checkBox.setChecked(true); } else { holder.checkBox.setChecked(false); } return convertView; } static class ViewHolder { private CheckBox checkBox; private TextView tvName; private ImageView ivExpand; public ViewHolder(View convertView) { checkBox = convertView.findViewById(R.id.cb); tvName = convertView.findViewById(R.id.tv_name); ivExpand = convertView.findViewById(R.id.iv_expand); } } }
也可以用RecycleView實(shí)現(xiàn),在我的項(xiàng)目里面都有。
以上是“Android如何實(shí)現(xiàn)多級(jí)樹(shù)形選擇列表”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!