Note that there are some explanatory texts on larger screens.

plurals
  1. POListview with or without convertview == null
    primarykey
    data
    text
    <p>I have a dilemma using </p> <pre><code>if (convertview==null){ (my code) } </code></pre> <p>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.</p> <p>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 <a href="http://bartinger.at/listview-with-sectionsseparators/" rel="nofollow">link</a>. The length of the list is good.</p> <p>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:</p> <p>public class DelftAdapter extends BaseAdapter {</p> <pre><code>private Activity activity; private List&lt;ListItem&gt; 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&lt;ListItem&gt; 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; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload