i have a listView with a custom BaseAdapter.Every list item has a clickable button.
private List items = new ArrayList();
public View getView(final int position, View convertView, ViewGroup parent) {
View v = null;
try {
v = inflater.inflate(R.layout.row, null);
TextView name = (TextView)v.findViewById(R.id.textView);
name.setText(items.get(position).getName());
imageButton = (ImageButton) v.findViewById(R.id.Button);
imageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// do something
}
});
} catch (Exception e) {
e.printStackTrace();
}
return v;
}
My problem is that the app freezes when i scroll the list.
How can i fix it?
You’re creating a new view everytime which is the complete opposite of what a listview does, it reuses views.
Remove
View v = nulland use theconvertViewparameter passed in.