Detailed examples of adding listening methods to controls in Android listview

Detailed examples of adding listening methods to controls in Android listview

Listview is a common control in Android. In listview, we usually need a template. This template does not refer to the living module, but configures the things displayed in listview. When we were doing the project today, we found that we wanted to add an ImageView monitoring method, and found that it collapsed, It may be that listview has not moved for a long time and forgot that it cannot directly call the controls of other XML files in the XML file of the main UI, even if listview uses this XML file.

[error demonstration]:

Directly call ImageView. This control is a listview control. It is called directly in the Java class file of non master view. This problem has not been known before.

[how to get]:

Use the monitoring method of the control in the listview monitoring method. The most important thing is to click listview to obtain the parent view of all the controls

In this way, you can use MSG = (ImageView) view. Findviewbyid (r.id.msg); We have obtained our control. The view is very important, which involves a knowledge. What if my activity setcontentview is not the view I want to use the control at present? The layouteinflator is used to instantiate the XML layout file of layout as a view class object.

There are three methods to obtain layoutinflator:

At this time, you may wonder:

difference:

Once setcontentview () is called, the layout will immediately display the UI; While inflate will only form the layout into an object implemented by the view class, and then use setcontentview (view) to display it when necessary. Generally, the interface is displayed through setcontentview () in an activity. However, if the control layout is set in a non activity, it needs to be loaded dynamically by layoutinflater.

The above is an example of adding events to Android listview. If you have any questions, please leave a message or communicate and discuss with our community. Thank you for reading. I hope it can help you. Thank you for your support to our site!

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