How to use listview in Android development tutorial

The first is the layout file. Two layout files are required here. One is the layout file main.xml corresponding to the activity where the list control is placed, and the other is the layout list corresponding to each line of information display in the listview_ The problem to be noted in item.xml is that the ID of listview control should use Android: id = "@ Android: ID / list" [note form]

main.xml

list_ item.xml

Then set the code in mainactivity: the basic idea is to add the data to the ArrayList first, and then set the simpleadapter adapter. Enter the following:

In addition, the method to respond to clicking on a row is to override the onlistitemclick method. According to the returned position (starting from 0):

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
分享
二维码
< <上一篇
下一篇>>