I have a ListView whose items can be removed by scrolling them. When an item scrolls, its database row is deleted, as well as its object in the adapter dataset and notifyDataSetChanged() called. The problem is that these objects have different heights - one can be single-line, the second can have four lines. Therefore, when I have some elements in the list, let's say:
1. One line
2. Two lines
3. Three lines
4. One line
And the second is removed, the third goes to its place (as expected), but is cut to two lines. And when the third one is removed, the height of the fourth element increases in accordance with the deleted element.
I found a way to fix this, but it's probably wrong - it creates a new view, even if the convertView is not null.
I wonder if this can be achieved in another convenient way.
Current adapter code:
public class CounterItemAdapter extends BaseAdapter{ private Activity activity; private ArrayList<CounterItem> data; private SQLiteOpenHelper helper; private static LayoutInflater inflater = null; public CounterItemAdapter(Activity activity, ArrayList<CounterItem> data, SQLiteOpenHelper helper) { this.activity = activity; this.data = data; this.helper = helper; inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public int getCount() { return data.size(); } @Override public CounterItem getItem(int position) { return data.get(position); } @Override public long getItemId(int position) { return getItem(position).getId(); } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView;
source share