Android ListView and Arrayadapter

Source: Internet
Author: User

Today, it's a simple question to discuss in the group, but the question really needs to be looked at carefully.

problem: Define a simplest arrayadapter, and the ListView in conjunction with the use of the kill item on the display of the simplest textview, a total of 6 item, a screen display 3, encountered the problem is that the program runs, There is no problem with clicking on the 3 item displayed on one screen, but when the swipe is over a screen, the Nullpointer will appear when you click on the item again.

Look at the Onitemlistener, it's written like this:

List.setonitemclicklistener (new  Onitemclicklistener () {@Overridepublicvoid int Long  = (TextView) list.getchildat (position). Findviewbyid (R.id.text); TV. SetText ("");

The problem is list.getchildat (position). Findviewbyid (), this sentence, when the 4th item is added, the value of position is 4, but the Debug discovery list only 3 child is not empty, So the 4th one is empty, check it out. There is a caching mechanism for the ListView of Android, the ListView only caches the first screen item, and when the item is loaded back, it will only reuse the previous layout. So the maximum number of components stored in the ListView is only the last position of the first screen.

So after the item to want to listen to the normal corresponding, do not look for the control from the ListView, you should click on the view to find, change to View.findviewbyid (), you can.

This simple look: http://www.cnblogs.com/over140/archive/2011/03/23/1991100.html

Android ListView and Arrayadapter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.