0

Here is my confusion: I hava a listview with 8 same items.I add one by one by add button..And it will new 8 convertView at first.Totally, I add 15 items.But when I scrolled down when the 11th item turned up, it new a convertView once again..Why it don't just use the convertView from the recycler?


Here are parts of the codes:

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater layoutInflater = (LayoutInflater)this.mcontext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = layoutInflater.inflate(R.layout.city_item, parent, false);
        viewHolder = new ViewHolder();
        Log.d("test", "new one" + position);
        viewHolder.checkBox = (CheckBox)convertView.findViewById(R.id.checkbox);
        viewHolder.textView = (TextView)convertView.findViewById(R.id.tv_city);
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder)convertView.getTag();
    }
}

Here are the pics:

Ziem
  • 6,579
  • 8
  • 53
  • 86
thirtvanke
  • 39
  • 2
  • 5
  • I've seen some articels about convertView reuse,but them did not mention how does the recycler exactly work. – thirtvanke Feb 21 '16 at 15:56

1 Answers1

0

ListView does not work on the principle of recycling. You can use RecyclerViews for this purpose. Checkout here

Community
  • 1
  • 1
Sarfaraz
  • 324
  • 1
  • 3
  • 13