I have a list view with custom adapter. The custom adater is just TextView and 2 ImageButtons.
When the ImageButton is clicked I want its image to toggle. This works however, when I scroll down some random items are also toggled. 

So I thought it's related to relativeness of items positions on the screen. So I assigned a tag to each ImageButton that corresponds to its position in the list view. Then I use the following code to correctly select necessary item:

```
    int firstVisiblePos = listView.getFirstVisiblePosition();
    int viewPos = 0;
    int position = Integer.parseInt(v.getTag().toString());
    Toast.makeText(this, v.getTag().toString(), Toast.LENGTH_SHORT).show();
    for (int i = 0; i < listView.getChildCount(); i++) {
        viewPos = firstVisiblePos + i;
        if (viewPos == position) {              
            relativeLayout = (RelativeLayout) listView.getChildAt(position);
            break;
        }
    }

```

Yet I still experience the same behaviour. 
Any help is appreciated.

UPD: 

```
public class CustomAdapter extends BaseAdapter {
private ArrayList<String> data;
private Activity myActivity;
private LayoutInflater inflater;

public CustomAdapter(Activity activity, ArrayList<String> data) {
    this.myActivity = activity;
    this.data = data;
    this.inflater = (LayoutInflater) myActivity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getCount() {
    return data.size();
}

@Override
public Object getItem(int position) {
    return data.get(position);
}

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

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.list_row, null);
    }

    TextView proverb = (TextView) convertView.findViewById(R.id.title);
    proverb.setText(data.get(position));
    proverb.setTextSize(android.util.TypedValue.COMPLEX_UNIT_SP, 14);
    proverb.setTypeface(MainActivity.tf, 1);
    ImageButton favBtn = (ImageButton) convertView.findViewById(R.id.btn_favorite);
    if(MainActivity.favorites.contains(data.get(position))){
        // favorite, set fav icon
        favBtn.setImageDrawable(myActivity.getResources().getDrawable(R.drawable.fav));         
    }       
    favBtn.setTag(position);
    return convertView;
}

```

}