Sometimes in android, when creating custom adapters for listviews, programmers use a static class (usually named "Holder") that holds instances for custom sub-views. For example:
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final Holder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.child_item, null);
CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.checkBox_child);
TextView tvName = (TextView) convertView.findViewById(R.id.textView_child_episodeName);
holder = new Holder();
holder.checkBox = checkBox;
holder.tvName = tvName;
convertView.setTag(holder);
}
else {
holder = (Holder) convertView.getTag();
}
...
...
return convertView;
}
static class Holder {
TextView tvName;
CheckBox checkBox;
}
I understand this is a lot faster because each reference is saved and created only once.
In my code, instead of a static "Holder" class, I created a non-static class:
public class Holder {
private TextView tvName;
private CheckBox checkBox;
public TextView getTextView() {
return tvName;
}
public void setTextView(TextView tv) {
this.tvName = tv;
}
public CheckBox getCheckBox() {
return checkBox;
}
public void setProgressCheckBox (CheckBox cb) {
this.checkBox = cb;
}
}
And I use this non-static class. Now the question is - does it work the same? And if not, will setting the inner non-static class fields static make it basically the same in terms of speed?