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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:46:49+00:00 2026-06-05T00:46:49+00:00

I have custom listview. When I scroll my listview, android keeps in memory (as

  • 0

I have custom listview. When I scroll my listview, android keeps in memory (as far as I understand) items which is displaying on screen and doesn’t keep items which is hidden (not scrolled to).

In my case (I think) keeping all list items would be better than generating hidden items.

So, how to “tell” android to keep all items in memory? (15-20 items). PS: if it’s wasting of resources, I’d like just to try.

My adapter (some funcs):

private View newView(Context context, ViewGroup parent) {
  LayoutInflater layoutInflater = LayoutInflater.from(context);
  return layoutInflater.inflate(R.layout.myl,parent,false);
}
public View getView(int position,View convertView,ViewGroup parent) {
  View view=null;
  if(convertView!=null) view=convertView; else view=newView(context,parent);
  HashMap<String,String> d=new HashMap<String,String>();
  d=data.get(position); 
  String qweqwe=d.get("qweqwe"); //9 more lines like this.
  TextView txt=(TextView)view.findViewById(R.id.mfmf); //
  txt.setText(qweqwe); //
  txt.setTypeface(mlf); //5 more blocks of 3 lines like this.
  if (smth.equals("0")){
    view.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.mvmv));
  } else {
    view.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.mvmv2));
  }
  return view;
}
  • 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-05T00:46:52+00:00Added an answer on June 5, 2026 at 12:46 am

    Ok.. there are some things that can be optimized here, instead of trying to fix lag with workarounds 🙂

    You should implement a static class, where you can store references to the Views in your myl.xml. For each View you want to manipulate in myl.xml, you create a View in this static class. So if you have 10 TextViews, you fill this class with 10 TextViews.

    static class AdapterViewsHolder {
        TextView txt1;
        TextView txt2;
        TextView txt3;
        ...
        ImageView img1;
        ... etc etc.
    }
    

    In the adapter, you now only do the findViewById() calls if the convertView is null. findViewById() is not cheap, so limiting the amount of calls increases performance.

    private HashMap<String, String> mData;
    private LayoutInflater mInflater;
    private TypeFace mCustomTypeFace;
    
    // Some contructor for passing data into the Adapter.
    public BaseAdapter(HashMap<String, String> data, Context ctx) {
        mData = data;
        mInflater = LayoutInflater.from(ctx);
        mCustomTypeFace = Typeface.createFromAsset(ctx.getAssets(), "yourTypeFace.ttf");
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        // This AdapterViewsHolder will hold references to your views, so you don't have to 
        // call findViewById() all the time :)
        AdapterViewsHolder holder;
    
        // Check if convertView is null
        if(convertView == null) {
            // If it is, we have to inflate a new view. You can probably use the newView() call here if you want.
            convertView = mInflater.inflate(R.layout.myl, null);
    
            // Initialize the holder
            holder = new AdapterViewsHolder();
    
            // Now we do the smart thing: We store references to the views we need, in the  holder. Just find all the views you need, by id.
            holder.txt1 = (TextView) convertView.findViewById(R.id.textview1);
            holder.txt2 = (TextView) convertView.findViewById(R.id.textview2);
            ...
            holder.img1 = (ImageView) convertView.findViewById(R.id.imageview1);
    
            // Store the holder in the convertViews tag
            convertView.setTag(holder);
        }
        else {
            // If convertView is not null, we can get get the holder we stored in the tag.
            // This holder now contains references to all the views we need :)
            holder = (AdapterViewsHolder) convertView.getTag();
        }
    
    
    
        // Now we can start assigning values to the textviews and the imageviews etc etc
        holder.txt1.setText(mData.get(position));
        ...
        holder.txt1.setTypeface(mCustomTypeFace);
        ...
        holder.img1.setImageResource("IMAGE RESOURCE HERE");  
    
        if(someThing.equals("sometext") {
             convertView.setBackgroundDrawable(somedrawable);
        }
        else {
             convertView.setBackgroundDrawable(someotherdrawable);
        }
    
        // Finally, we return the convertView
        return convertView;
    }
    

    I do not know how your data is organized, so you have to change this code a bit.

    One more thing that can cause lag is the android:cacheColorHint xml attribute. Usually you set this to either the same color as you application background, or transparent. Setting it transparent have been known to cause rapid Garbage collections on some occasions.

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

Sidebar

Related Questions

I have a custom ListView in which each row.xml looks like this: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I have a custom listview with three items. One of them is like Add
I have an activity with a ListView which is populated through a custom ArrayAdapter.
I have a custom ListView that uses a custom ArrayAdapter (which basically just overrides
Actually I have created a custom ListView . I want to add items to
I have a custom ListView Adapter , with which I'm creating rows for a
I have created a custom ArrayAdapter to display data within ListView items from an
I have one custom ListView which contains one ImageView and one TextView, and I
I have a custom ListView adapter which implements an ImageThreadLoader class. Unfortunately, the class
I have a custom ListView adapter which implements an ImageThreadLoader class. Unfortunately the class

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.