Implementation method of Android tree control

On the PC, we are used to the tree control because it can clearly show the hierarchical results between various nodes. However, on the Android platform, the system does not provide such a control, but only listview. However, this effect can be achieved by rewriting the adapter bound to the listview.

A listview needs to be bound with an adapter to manage data. Here, take baseadapter as an example. Inheriting an adapter requires rewriting four functions, two of which are more important: 1 Public int getcount()// This function returns the number of listitems in listview. 2 public view getview (int position, view view, ViewGroup arg2) / / is responsible for drawing each item. If getcount () returns 10, getview () will be called 10 times.

First, develop your own data structure:

Then write your own adapter

listview_ item. xml

Effect achieved:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>