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 7868279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:57:03+00:00 2026-06-03T00:57:03+00:00

I implemented a custom Adapter to create a dialog box that displays info related

  • 0

I implemented a custom Adapter to create a dialog box that displays info related with locations (each entry of the dialogue consists of an image, a text field to display the address and a text field to show the city and country .) In the getView (…) method of the adapter besides using the ViewHolder pattern I use the SoftReference class to save a reference to the views created so the GC can be eliminated any of them before an OutOfMemoryError occurs. My goal is to build a faster and efficient cache. Below the code of my custom Adapter:

public class LocationsAdapter extends ArrayAdapter<LocationInfo> {

Context context;
int layourResourceId;
List<LocationInfo> locations;

public LocationsAdapter(Context context, int layourResourceId,
        List<LocationInfo> locations) {
    super(context, layourResourceId, locations);

    this.context = context;
    this.layourResourceId = layourResourceId;
    this.locations = locations;
}

@Override
public View getView(int position, View row, ViewGroup parent) {

    LocationItemHolder holder = null;

    if (row != null && ((SoftReference<LocationItemHolder>) row.getTag()).get() != null) {

        holder = (LocationItemHolder) ((SoftReference<LocationItemHolder>) row.getTag()).get();

    } else {

        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        row = inflater.inflate(layourResourceId, parent, false);

        holder = new LocationItemHolder();
        holder.imgMarker = (ImageView) row.findViewById(R.id.imgMarker);
        holder.txtNameStreet = (TextView) row
                .findViewById(R.id.txtNameStreet);
        holder.txtRegion = (TextView) row.findViewById(R.id.txtRegion);

        row.setTag(new SoftReference<LocationItemHolder>(holder));
    }

    LocationInfo location = locations.get(position);
    holder.imgMarker.setImageResource(location.getMarkerId());
    holder.txtNameStreet.setText(location.getNameStreet());
    holder.txtRegion.setText(location.getRegion());

    return row;
}

class LocationItemHolder {
    ImageView imgMarker;
    TextView txtNameStreet;
    TextView txtRegion;
}
}

I am very interested in making things as efficient as possible. Although the code make what I want I’m not sure if I’m making good use SoftReference class. For example the sentence (LocationItemHolder) ((SoftReference ) row.getTag ()).get() I think it makes the cache ineffective because of the number of methods to be called to retrieve the desired object each time the method getView is invoked, also requires multiple castings. Can that sentence make inefficient the cache?. Is it advisable to use SoftReference in the context of an adapter in Android?

Thanks in advance for your answers 😀

  • 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-06-03T00:57:04+00:00Added an answer on June 3, 2026 at 12:57 am

    As far as I can tell, there’s no point in using SoftReferences here. If you’re correctly recycling views (seems like you are), you will only have a few instances of LocationItemHolder, which will always be the same (within the same adapter). The only time they will become invalidated is when the adapter ceases to be used.

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

Sidebar

Related Questions

I had implemented a custom Gallery with custom Adapter. My Requirement is that however
I managed to implement a GalleryView, create a custom Adapter that returns a ListView
I have a custom adapter that visualize each row in the list of Orders.
I've a custom adapter implemented for my ListView . How do I extract objects
A problem with a custom view adapter that implement listeners form button and chronometer.
I would like to create a set of custom controls that are basically image
I have implemented a custom list view which looks like the twitter timeline. adapter
I am creating a Spinner instance that I bind to my own custom adapter
I have implemented an application with Custom base adapter for display data in list
I'm writing a custom view to get around the bug that displays the wrong

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.