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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:55:29+00:00 2026-06-08T04:55:29+00:00

I have a dilemma using if (convertview==null){ (my code) } or not. Without this

  • 0

I have a dilemma using

if (convertview==null){
(my code)
}

or not. Without this piece of code, my listview is not very fast, it locks for a few ms sometimes and you can easy notice this in use. It just doesn’t work how its meant to work.

But when this piece of code, my listitems will start recounting after a while (10 or so) and i have a few returning listitems in my list (with the header i used). I used this tutorial for getting my listview with sections link. The length of the list is good.

Ofcourse my list is totally useless with a view repeating items (nicely sectioned by the way) but i also dont want it to be slow.
Does anyone know what to do?
Below is my adapter:

public class DelftAdapter extends BaseAdapter {

private Activity activity;
private  List<ListItem> listItems;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader; 
private final int[] bgColors = new int[] { R.color.list_odd, R.color.list_even };


public DelftAdapter(Activity a, ArrayList<ListItem> li) {
    activity = a;
    listItems = li;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageLoader=new ImageLoader(activity.getApplicationContext());

}

public int getCount() {
    return listItems.size();
}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}




public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;


        final ListItem li = listItems.get(position); 
        if (li != null) {
            if(li.isSection()){ // is sectionheader
                SectionItem si = (SectionItem)li; 
                vi = inflater.inflate(R.layout.sectionedlistitem, null);
                vi.setOnClickListener(null);
                vi.setOnLongClickListener(null);
                vi.setLongClickable(false);
                final TextView sectionView = (TextView) vi.findViewById(R.id.list_header_title);
                sectionView.setText(si.getTitle());
            }else{ // no sectionheader
                ListData ld = (ListData)li;
            vi = inflater.inflate(R.layout.singlelistitem, null);
        TextView tvNames=(TextView)vi.findViewById(R.id.tvname); 
        TextView tvTip=(TextView)vi.findViewById(R.id.tvtip);
        ImageView image=(ImageView)vi.findViewById(R.id.image);
        tvNames.setText(ld.name);
        tvTip.setText(ld.tip);
            if (listItems.get(position) != null ){
                imageLoader.DisplayImage(ld.photoUrl, image);
                }
                else{
                image.setImageURI(Uri.fromFile(new File("//assets/eten.png")));
            }
        // alternating colors
        int colorPos = position % bgColors.length;
             vi.setBackgroundResource(bgColors[colorPos]);
            }
    }
        return vi;

}
}
  • 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-08T04:55:32+00:00Added an answer on June 8, 2026 at 4:55 am

    Consider using getItemViewType() and getViewTypeCount() with recycling convertView. Those are used when you have list items with various layouts. You definitely should recycle convertView.

    See also http://android.amberfog.com/?p=296

    In your case:

        private static final int TYPE_ITEM = 0;
        private static final int TYPE_SECTION = 1;
    
        @Override
        public int getItemViewType(int position) {
            return listItems.get(position).isSection() ? TYPE_SECTION : TYPE_ITEM
        }
    
        @Override
        public int getViewTypeCount() {
            return 2;  // sectionheader and regular item
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            int type = getItemViewType(position);
            if (convertView == null) {
                switch (type) {
                    case TYPE_ITEM:
                        convertView = mInflater.inflate(R.layout.singlelistitem, null);
                        ...
                        break;
                    case TYPE_SECTION:
                        convertView = mInflater.inflate(R.layout.sectionedlistitem, null);
                        ...
                        break;
                }
            } else {
                ...
            }
            return convertView;
        }
    

    Also use ViewHolder pattern to achieve better performance.

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

Sidebar

Related Questions

We have a dilemma; developing desktop application using Matisse or Jigloo.. Matisse has this
I have this dilemma many times - and I would like one time and
Here's my dilemma: I have two types of routes which are semantically very different,
So, the latest dilemma I am facing: I am using jQuery DatePick (not DatePicker)
I have a dilemma with this, I am designing a project and basically it
I have a difficult dilemma. I implemented a java application using Netbeans while implementing
I have a strange dilemma.... First of all, I am stuck using XPath 1.0
I have some kind of dilemma. I'm using: MSVS 2008 Qt 4.7.3 (with Qt
I have what I consider to be a strange dilemma, although YMMV. I'm using
I have a richTextBox I am using to perform some syntax highlighting. This is

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.