Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6813391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:33:53+00:00 2026-05-26T20:33:53+00:00

I have a listview where each list item can contain 1 or more clickable

  • 0

I have a listview where each list item can contain 1 or more clickable images. Clicking them starts an activity that shows a full screen version of the image.

The following code (slightly simplified) sets up the OnClickListeners within my GetView() implementation, for each image in each ListItem. This worked perfectly.

ImageView imageView = (ImageView)convertView.findViewById(R.id.image_res);
imageView.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        ActivityLauncher.startPhotoViewerActivity(mContext, item);
    }
});

However, to improve performance, I decided to store each view in memory after constructing it the first time. I do this instead of using convertView because there are 4-5 different types of Views and they are sometimes dynamically constructed in code hence making re-use difficult.

As soon as I start storing the views in memory and then returning the already constructed views during subsequent calls to getView() based on the position, the performance significantly improves but the OnClickListeners start behaving funky.

Specifically, now when a given image is tapped, the OnClickListener for it may fire immediately or not at all. In the cases where it does not fire immediately, it may fire as soon as one starts scrolling. If this doesn’t trigger the OnClickListener to run, clicking back (to quit the activity) may trigger it. If this doesn’t trigger it, then closing all activities by pressing BACK) and then re-entering the app will trigger all the queued OnClickListeners. In one case I clicked 25 times on various images with no result. Then I closed all the activities and then clicked the application icon once again which opened all 25 image previews.

Any idea as to what is causing this? What is interesting to me is that the OnClickListeners are obviously set correctly because they do open the photo viewer activity at some point in time. The wrong image is never opened and there is never a case where they NEVER fire. The problem is that they may fire immediately or much later.

Is it not recommended to save the Views for each list item and return them based on position from within getView() like I am doing? Any help is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:33:54+00:00Added an answer on May 26, 2026 at 8:33 pm

    Watch the talk on ListViews given at Google I/O. At 13:45, they specifically warn against caching views and returning them. If one does this, it can lead to strange behavior, which is exactly what I am experiencing. Given this, the question is moot.

    http://www.youtube.com/watch?v=wDBM6wVEO70

    Hope this helps someone in the future avoid the same pitfalls. Caching views is NOT RECOMMENDED!!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity that extends ListView. I populate my list with the results
I have a ListView that inflate for each row a xml that contain a
I have listview with combox=true containg images. Each item is assigned a tag. I
I have a listview which contains maybe 15 rows. Each row (list item) contains
I have a listview and each item has a title, some info, and a
I have a listview with several items that are created dynamically, each has two
I have a listview that contains values from webservice.Each page contains only 10 listitems
I have a listview where each item correlates to an instance of an item
I have a listview with custom rows and that extends SimpleAdapter. Each row consist
I have a ListView-like control that displays a list of items of various heights.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.